Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image 如何确定PFFile是视频还是图像?_Image_Swift_Video_Parse Platform_Pffile - Fatal编程技术网

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

Image 如何确定PFFile是视频还是图像?,image,swift,video,parse-platform,pffile,Image,Swift,Video,Parse Platform,Pffile,我正在IO中使用Parse和 想知道我如何确定我得到的文件是视频还是图像有什么想法?有什么建议吗 这是我到目前为止得到的 if let value = allPost[indexPath.row]["imageFile"] as? PFFile { let PFFileURLFromParse = value.url let fileUrl = NSURL(string: PFFileURLFromParse!) func thumb

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

这是我到目前为止得到的

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

以下是我到目前为止得到的结果

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

我欢迎这样做。你有没有试过什么,有没有代码给我们看?到目前为止,你看过哪些教程或问题?如果您提出与您遇到的问题(通常是代码问题)相关的特定问题,您更有可能获得帮助。文件是如何创建的?哪个对象拥有对它的引用?您可以使用PFFile*file获得PFFile的扩展名;[file.name路径扩展名];重写func tableView(tableView:UITableView,cellForRowAtIndexPath:nsindepath,object:PFObject!)->PFTableViewCell?{let cell=tableView.dequeueReusableCellWithIdentifier(“FeedPostCell”,forIndexPath:indexPath)as!NewsFeedCell cell.alpha=0让FeedPost=object as!Post cell.postmage.file=FeedPost.PFFile这是我在代码中写的内容帖子是一个NSObjectI欢迎访问。你有没有尝试过什么,有没有代码向我们展示过?到目前为止你看过哪些教程或问题?如果你问一些具体问题,请联系我们对于您遇到的问题,通常是代码问题,您更有可能获得帮助。文件是如何创建的?哪个对象拥有对它的引用?您可以使用PFFile*file;[file.name path extension];override func tableView(tableView:UITableView,cellForRowAtIndexPath:nsindepath,object:PFObject!)->PFTableViewCell?{let cell=tableView.dequeueReusableCellWithIdentifier(“FeedPostCell”,forIndexPath:indexPath)as!NewsFeedCell.alpha=0 let FeedPost=object as!Post cell.postImage.file=FeedPost.PFFile以下是我在代码中编写的内容Post是一个NSObject