1
我正在用Parse創建IO的應用程序,並且 想知道如何確定我得到的文件是視頻還是圖像任何想法?任何建議?如何確定PFFile是視頻還是圖像?
我正在用Parse創建IO的應用程序,並且 想知道如何確定我得到的文件是視頻還是圖像任何想法?任何建議?如何確定PFFile是視頻還是圖像?
這裏就是我有這麼遠
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 {}
我歡迎來到SO。你有沒有嘗試過任何代碼給我們看?你到目前爲止看過哪些教程或SO問題?如果您通過代碼詢問與您遇到的問題有關的具體問題,則您更有可能獲得幫助。 – Deepend
文件是如何創建的?什麼對象擁有對它的引用? – Wain
你可以通過使用PFFile *文件來獲得PFFile的擴展名; [file.name pathExtension]; –