I'm creating an application in IO's with Parse and would like to know how can i determine if the file that i get is a Video or an image any ideas? any suggestion ?
Asked
Active
Viewed 142 times
1
-
I welcome to SO. Have you tried anything, any code to show us? What tutorials or SO questions have you looked at so far? if you ask specific questions relating to a problem you are having, usually with code, you are much more likely to get help. – Deepend Nov 15 '15 at 16:46
-
How is the file created? What object owns the reference to it? – Wain Nov 15 '15 at 17:40
-
you can get extension of PFFile by using PFFile *file; [file.name pathExtension]; – Hardik Shekhat Nov 16 '15 at 08:57
-
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject!) -> PFTableViewCell? { let cell = tableView.dequeueReusableCellWithIdentifier("FeedPostCell", forIndexPath: indexPath) as! NewsFeedCell cell.alpha = 0 let FeedPost = object as! Post cell.postImage.file = FeedPost.PFFile here's what what i written in my code the post is an NSObject – bernard rayoso Nov 29 '15 at 12:37
1 Answers
0
here's what I've got so far
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()
}
// but the loading for cell is getting is too long how i put it in collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {}

bernard rayoso
- 153
- 1
- 5