我正在用Parse和
想知道如何确定我得到的文件是视频还是图像有什么想法吗?有什么建议吗?
最佳答案
这是我到目前为止得到的
if let value = allPost[indexPath.row]["imageFile"] as? PFFile {
let PFFileURLFromParse = value.url
let fileUrl = NSURL(string: PFFileURLFromParse!)
func thumbnailImagePreview() -> UIImage?
{
let asset = AVURLAsset(URL: fileUrl!)
let imageGenerator = AVAssetImageGenerator(asset: asset)
imageGenerator.appliesPreferredTrackTransform = true
imageGenerator.apertureMode = AVAssetImageGeneratorApertureModeEncodedPixels
do {
let time: CMTime = CMTime(seconds: 0.0, preferredTimescale:1)
let imageRef = try imageGenerator.copyCGImageAtTime(time, actualTime: nil)
return UIImage(CGImage: imageRef)
} catch {
return nil
}
}
if (fileUrl!.pathExtension!.lowercaseString == "mov"){
print("Parse image is a mov: \(fileUrl!.pathExtension!.lowercaseString)”);
fileExtenion = "mov";
cell.ImagePost.image = thumbnailImagePreview()
cell.ImagePost.loadInBackground()
print("fileExtenion is \(fileExtenion)")
}
else{
fileExtenion = ".png";
print("DEFAULTING TO file type, Parse image is a png: \(fileUrl!.pathExtension!.lowercaseString)");
}
cell.ImagePost.file = value
cell.ImagePost.loadInBackground()
}
//但单元格的加载时间太长,无法将其放入collectionView(collectionView:UICollectionView,cellForItemAtIndexPath indexPath:NSIndexPath)->UICollectionView cell{}