函数调用参数类型与网址类型

时间:2017-09-21 22:08:55

标签: ios swift

我最近在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))
    })
}

下面提供调用(generateThumbnail)的函数playVideo。当我尝试编译程序时,它在playVideo中使用函数调用“generateThumbnail(url:URL,fromTime:Float64(grabTime))”失败并显示错误:

  

“无法将'URL.Type'类型的值转换为预期的参数类型'URL'

任何人都可以帮忙解决此问题吗?我在这个网站上查看过这种类型的其他错误,但它们似乎没有涵盖这些特殊情况,这就是我现在提出这个错误的原因。

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 个答案:

答案 0 :(得分:0)

更改

    generateThumbnail(url: URL, fromTime: Float64(grabTime))

    generateThumbnail(url: url, fromTime: Float64(grabTime))