这是我的代码的一部分(用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
}
当我运行它时,我收到此错误:
错误域= AVFoundationErrorDomain代码= -11850“操作已停止”UserInfo = {NSLocalizedFailureReason =服务器未正确配置。,NSLocalizedDescription =操作已停止,NSUnderlyingError = 0x61c00044fbd0 {错误域= NSOSStatusErrorDomain代码= -12939“(null)” }}