It's part of my code (written in Swift 4, xcode 9.2), where I want to do that.
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
}
and getThumnailImage function
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
}
When I run it, I get this error:
Error Domain=AVFoundationErrorDomain Code=-11850 "Operation Stopped" UserInfo={NSLocalizedFailureReason=The server is not correctly configured., NSLocalizedDescription=Operation Stopped, NSUnderlyingError=0x61c00044fbd0 {Error Domain=NSOSStatusErrorDomain Code=-12939 "(null)"}}