下面是我用来尝试从资源库快速加载视频的代码。我一直在获取该文件不存在,但我知道它确实存在。它是从相机胶卷中选择的视频的uri。任何帮助将不胜感激。
let filePath = "assets-library://asset/asset.MOV?id=F623834F-9E3F-4EF6-9348-E1AF8E86DD10&ext=MOV"
let fileUrl = URL(fileURLWithPath: filePath)
let videoAsset = PHAsset.fetchAssets(withALAssetURLs: [fileUrl], options: nil)
if videoAsset.count > 0 {
guard (videoAsset[0].mediaType == .video) else {
print("Not a valid video media type")
return
}
PHCachingImageManager().requestAVAsset(forVideo: videoAsset[0], options: nil) { (asset, audioMix, args) in
let asset = asset as! AVURLAsset
DispatchQueue.main.async {
player = AVPlayer(url: asset.url)
let playerLayer = videoPlayerView.playerLayer
playerLayer.player = player
playerLayer.videoGravity = .resizeAspectFill
player?.play()
}
}
} else {
print("video could not be found")
}