簡體   English   中英

如何確定PFFile是視頻還是圖像?

[英]How to determine if PFFile is Video or Image?

我正在使用Parse在IO中創建一個應用程序,想知道如何確定獲取的文件是視頻還是圖像有什么想法? 有什么建議嗎?

這是到目前為止我得到的

      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 {}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM