I have recently started programming in Swift 4 and have a compile error to resolve. I have an @IBACTION function called playVideo which plays a video but I want to be able to capture frames from the video as well for further processing. This @IBAction function is shown below:
我最近开始在Swift 4中编程并且有一个编译错误要解决。我有一个名为playVideo的@IBACTION函数播放视频,但我希望能够从视频中捕获帧以及进一步处理。这个@IBAction函数如下所示:
@IBAction func playVideo (_ sender: AnyObject) {
self.present(self.playerController, animated:true, completion: {
self.playerController.player?.play()
var grabTime = 1.22
generateThumbnail(url: URL, fromTime: Float64(grabTime))
})
}
The function playVideo which calls (generateThumbnail) is provided below. When I attempt to compile the program it fails with the function call "generateThumbnail(url:URL, fromTime: Float64(grabTime))" in playVideo with the error:
调用(generateThumbnail)的函数playVideo如下所示。当我尝试编译程序时,它在playVideo中使用函数调用“generateThumbnail(url:URL,fromTime:Float64(grabTime))”失败,错误如下:
"cannot convert value of type 'URL.Type' to expected argument type 'URL'
“无法将'URL.Type'类型的值转换为预期的参数类型'URL'
Can anyone help to resolve this issue? I have looked on this site for other errors of this type but they don't seem to cover these particular circumstances which is why I raised this now.
任何人都可以帮忙解决这个问题吗?我在这个网站上看过这种类型的其他错误,但它们似乎并没有涵盖这些特殊情况,这就是我现在提出这个问题的原因。
func generateThumbnail(url: URL, fromTime:Float64) -> UIImage? {
let asset :AVAsset = AVAsset(url: url)
let assetImgGenerate : AVAssetImageGenerator = AVAssetImageGenerator(asset: asset)
assetImgGenerate.appliesPreferredTrackTransform = true
assetImgGenerate.requestedTimeToleranceAfter = kCMTimeZero;
assetImgGenerate.requestedTimeToleranceBefore = kCMTimeZero;
let time : CMTime = CMTimeMakeWithSeconds(fromTime, 600)
var img: CGImage?
do {
img = try assetImgGenerate.copyCGImage(at:time, actualTime: nil)
} catch {
}
if img != nil {
let frameImg : UIImage = UIImage(cgImage: img!)
return frameImg
} else {
return nil
}
}
1 个解决方案
#1
0
Change
generateThumbnail(url: URL, fromTime: Float64(grabTime))
To
generateThumbnail(url: url, fromTime: Float64(grabTime))
#1
0
Change
generateThumbnail(url: URL, fromTime: Float64(grabTime))
To
generateThumbnail(url: url, fromTime: Float64(grabTime))