在 Collection 中播放视频 查看失败
Play a Video in Collection View failed
我正在开发一个应用程序,我从 firebase link 获取视频。
为了能够显示和播放我正在使用此扩展程序的视频:
func generateThumbnailForVideoAtURL(filePathLocal: NSString) -> UIImage? {
let vidURL = NSURL(fileURLWithPath:filePathLocal as String)
let asset = AVURLAsset(url: vidURL as URL)
let generator = AVAssetImageGenerator(asset: asset)
generator.appliesPreferredTrackTransform = true
let timestamp = CMTime(seconds: 1, preferredTimescale: 60)
do {
let imageRef = try generator.copyCGImage(at: timestamp, actualTime: nil)
return UIImage(cgImage: imageRef)
} catch let error as NSError {
print("Image generation failed with error \(error)")
return nil
}
}
然后在cellAtIndexPath
中这样使用它:
if posts[indexPath.row].videoUrl != nil {
cell.videoView.generateThumbnailForVideoAtURL(filePathLocal: self.posts[indexPath.row].videoUrl as! NSString)
print("VIDEO IS: \(posts[indexPath.row].videoUrl)")
}
我收到这个错误:
Image generation failed with error Error Domain=NSURLErrorDomain Code=-1102 "You do not have permission to access the requested resource." UserInfo={NSLocalizedDescription=You do not have permission to access the requested resource., NSUnderlyingError=0x1c4046ff0 {Error Domain=NSOSStatusErrorDomain Code=-12660 "(null)"}}
这似乎是一个 UserInfo 描述,但我在我的 plist 中找不到任何内容来添加权限。这对其他人来说可能听起来很愚蠢,因为这就是我现在的感受,因为我找不到让它发挥作用的方法。请帮忙!
你应该使用这个
let vidURL = URL(string:filePathLocal as String)
而不是
let vidURL = NSURL(fileURLWithPath:filePathLocal as String)
我正在开发一个应用程序,我从 firebase link 获取视频。 为了能够显示和播放我正在使用此扩展程序的视频:
func generateThumbnailForVideoAtURL(filePathLocal: NSString) -> UIImage? {
let vidURL = NSURL(fileURLWithPath:filePathLocal as String)
let asset = AVURLAsset(url: vidURL as URL)
let generator = AVAssetImageGenerator(asset: asset)
generator.appliesPreferredTrackTransform = true
let timestamp = CMTime(seconds: 1, preferredTimescale: 60)
do {
let imageRef = try generator.copyCGImage(at: timestamp, actualTime: nil)
return UIImage(cgImage: imageRef)
} catch let error as NSError {
print("Image generation failed with error \(error)")
return nil
}
}
然后在cellAtIndexPath
中这样使用它:
if posts[indexPath.row].videoUrl != nil {
cell.videoView.generateThumbnailForVideoAtURL(filePathLocal: self.posts[indexPath.row].videoUrl as! NSString)
print("VIDEO IS: \(posts[indexPath.row].videoUrl)")
}
我收到这个错误:
Image generation failed with error Error Domain=NSURLErrorDomain Code=-1102 "You do not have permission to access the requested resource." UserInfo={NSLocalizedDescription=You do not have permission to access the requested resource., NSUnderlyingError=0x1c4046ff0 {Error Domain=NSOSStatusErrorDomain Code=-12660 "(null)"}}
这似乎是一个 UserInfo 描述,但我在我的 plist 中找不到任何内容来添加权限。这对其他人来说可能听起来很愚蠢,因为这就是我现在的感受,因为我找不到让它发挥作用的方法。请帮忙!
你应该使用这个
let vidURL = URL(string:filePathLocal as String)
而不是
let vidURL = NSURL(fileURLWithPath:filePathLocal as String)