我正在使用 Parse 在 IO 中创建一个应用程序,并且想知道如何确定我得到的文件是视频还是图像?有什么建议吗?
问问题
135 次
1 回答
0
这是我到目前为止所得到的
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) -> UICollectionViewCell {}
于 2015-11-30T07:20:20.673 回答