【问题标题】:How to determine if PFFile is Video or Image?如何确定 PFFile 是 Video 还是 Image?
【发布时间】:2016-02-16 17:38:28
【问题描述】:

我正在使用 Parse 和 想知道如何确定我得到的文件是视频还是图像?有什么建议吗?

【问题讨论】:

  • 我欢迎来到 SO。你有没有尝试过任何东西,任何代码给我们看?到目前为止,您看过哪些教程或 SO 问题?如果您提出与您遇到的问题相关的具体问题,通常是通过代码,您更有可能获得帮助。
  • 文件是如何创建的?哪个对象拥有对它的引用?
  • 您可以通过使用 PFFile *file 获得 PFFile 的扩展名; [文件名路径扩展];
  • 覆盖 func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath, object: PFObject!) -> PFTableViewCell? { 让 cell = tableView.dequeueReusableCellWithIdentifier("FeedPostCell", forIndexPath: indexPath) as! NewsFeedCell cell.alpha = 0 让 FeedPost = 对象为! Post cell.postImage.file = FeedPost.PFFile 这是我在我的代码中写的帖子是一个 NSObject

标签: image swift video parse-platform pffile


【解决方案1】:

这是我到目前为止所得到的

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

【讨论】:

    猜你喜欢
    • 2011-03-01
    • 1970-01-01
    • 2021-07-31
    • 2013-03-05
    • 1970-01-01
    • 1970-01-01
    • 2011-02-08
    • 2019-07-12
    相关资源
    最近更新 更多