如何确定PFFile是视频还是图像?

时间:2015-11-15 15:44:47

标签: image swift video parse-platform pffile

我正在使用Parse和。在IO中创建一个应用程序 想知道我怎么能确定我得到的文件是视频还是图像的任何想法?有什么建议吗?

1 个答案:

答案 0 :(得分: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 {}