这是我的代码(用 Swift 4,xcode 9.2 编写)的一部分,我想在其中执行此操作。
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "customCell", for: indexPath) as! CustomCollectionViewCell
if let thumbnailImage = getThumbnailImage(forUrl: str!) {
cell.imageView.image = thumbnailImage
}
cell.nameLabel.text = devices[indexPath.row].name.capitalized
print(devices[indexPath.row].url)
return cell
}
和 getThumnailImage 函数
func getThumbnailImage(forUrl url: URL) -> UIImage? {
let asset: AVAsset = AVAsset(url: url)
let imageGenerator = AVAssetImageGenerator(asset: asset)
do {
let thumbnailImage = try imageGenerator.copyCGImage(at: CMTimeMake(1, 60) , actualTime: nil)
return UIImage(cgImage: thumbnailImage)
} catch let error {
print(error)
}
return nil
}
当我运行它时,我得到这个错误:
Error Domain=AVFoundationErrorDomain Code=-11850 "Operation Stopped" UserInfo={NSLocalizedFailureReason=服务器配置不正确。, NSLocalizedDescription=Operation Stopped, NSUnderlyingError=0x61c00044fbd0 {Error Domain=NSOSStatusErrorDomain Code=-12939 "(null)"}}