gpt4 book ai didi

ios - 在 swift 中使用 PHImageManager (requestAVAssetForVideo)

转载 作者:行者123 更新时间:2023-11-28 12:58:54 25 4
gpt4 key购买 nike

我正在使用 objective-c 图像选择器图像选择器来选择时间流逝,但我正在快速进行。我只能访问 objective-c 代码,所以我使用了 objective-c 到 swift 转换器,但出现错误。

func qb_imagePickerController(imagePickerController: QBImagePickerController, didFinishPickingAssets assets: [AnyObject]) {
for asset in assets as! [PHAsset] {
PHImageManager.defaultManager().requestAVAssetForVideo(asset, options: nil, resultHandler: {(avAsset: AVAsset, audioMix: AVAudioMix, info: [NSObject : AnyObject]) -> Void in
var url: NSURL = NSURL(string: "\(asset)")!
var avAsset: AVURLAsset = AVURLAsset(URL: url, options: nil)
var playerItem: AVPlayerItem = AVPlayerItem(asset: avAsset)
var videoPlayer: AVPlayer = AVPlayer(playerItem: playerItem)
videoPlayer.play()
})
}
self.dismissViewControllerAnimated(true, completion: { _ in })
}

这是我目前的代码。我收到的错误如下。

Cannot convert value of type '(AVAsset, AVAudioMix, [NSObject : AnyObject]) -> Void' to expected argument type '(AVAsset?, AVAudioMix?, [NSObject : AnyObject]?) -> Void'

最佳答案

查看 requestAVAssetForVideo:options:resultHandler: 的文档 您拥有的 resultHandler 与所需的签名不匹配。

改变这一行:

PHImageManager.defaultManager().requestAVAssetForVideo(asset, options: nil, resultHandler: {(avAsset: AVAsset, audioMix: AVAudioMix, info: [NSObject : AnyObject]) -> Void in

到:

PHImageManager.defaultManager().requestAVAssetForVideo(asset, options: nil, resultHandler: {(avAsset: AVAsset?, audioMix: AVAudioMix?, info: [NSObject : AnyObject]?) -> Void in

注意在预期位置添加 ?

关于ios - 在 swift 中使用 PHImageManager (requestAVAssetForVideo),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34364193/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com