0

I am working on an app where I am getting videos from a firebase link. To be able to display and play the video I am using this extension:

func generateThumbnailForVideoAtURL(filePathLocal: NSString) -> UIImage? {

    let vidURL = NSURL(fileURLWithPath:filePathLocal as String)
    let asset = AVURLAsset(url: vidURL as URL)
    let generator = AVAssetImageGenerator(asset: asset)
    generator.appliesPreferredTrackTransform = true
    let timestamp = CMTime(seconds: 1, preferredTimescale: 60)
    do {
        let imageRef = try generator.copyCGImage(at: timestamp, actualTime: nil)
        return UIImage(cgImage: imageRef)
    } catch let error as NSError {
        print("Image generation failed with error \(error)")
        return nil
    }
}

And then using it like this in cellAtIndexPath:

if posts[indexPath.row].videoUrl != nil {
            cell.videoView.generateThumbnailForVideoAtURL(filePathLocal: self.posts[indexPath.row].videoUrl as! NSString)
            print("VIDEO IS: \(posts[indexPath.row].videoUrl)")
}

I am getting this error:

Image generation failed with error Error Domain=NSURLErrorDomain Code=-1102 "You do not have permission to access the requested resource." UserInfo={NSLocalizedDescription=You do not have permission to access the requested resource., NSUnderlyingError=0x1c4046ff0 {Error Domain=NSOSStatusErrorDomain Code=-12660 "(null)"}}

It seems like a UserInfo description, but I can not find anything in my plist to add for permission. It may just sound stupid for somebody else because this is how I feel now as I can't find a way to make it work. Please help!

Gaurav Bharti
  • 1,065
  • 1
  • 14
  • 22
Marian Petrisor
  • 262
  • 2
  • 19
  • did you solve the problem? Probably how you use the URL is not conventional. You might have to use firebase cloud functions to generate thumbnails in the server and use that images to your iOS app. [Here is a similar case as yours](https://stackoverflow.com/questions/37387551/ios-swift-error-domain-nsosstatuserrordomain-code-12792). If you already solve the issue please let me know – Imrul Kayes Sep 13 '18 at 17:58
  • Hi! Yes, the way I got the Url from the server was the problem. I didn't convert it properly into URL – Marian Petrisor Sep 13 '18 at 20:47

1 Answers1

2

You should use this

let vidURL = URL(string:filePathLocal as String)

instead of

let vidURL = NSURL(fileURLWithPath:filePathLocal as String)
Werner Henze
  • 16,404
  • 12
  • 44
  • 69