Posts

Post not yet marked as solved
0 Replies
283 Views
I am requesting videos using using PHImageManager. For some I get status .readyToPlay, but for others I get status .failed, and error code 257. As I open the assets on Photos, go back to my app, then I am able to play those assets. What am I missing? The request: PHImageManager.requestPlayerItem(forVideo: asset, options: options) { avPlayerItem, dictionary in guard avPlayerItem != nil else { return } self.avPlayerItem = playerItem self.avPlayerItem?.addObserver(self, forKeyPath: #keyPath(AVPlayerItem.status), options: [.old, .new], context: &self.playerItemContext) self.avPlayer = AVPlayer(playerItem: self.avPlayerItem!) } The options for videos are: var videoViewOptions : () -> PHVideoRequestOptions = {     let options = PHVideoRequestOptions()     options.version = .current     options.isNetworkAccessAllowed = true     options.deliveryMode = .automatic     return options   } The observer:    override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {     guard context == &playerItemContext else {       super.observeValue(forKeyPath: keyPath, of: object, change: change, context: context)       return     }           guard keyPath == #keyPath(AVPlayerItem.status) else {       return     }             let status: AVPlayerItem.Status           // Get the status change from the change dictionary     if let statusNumber = change?[.newKey] as? NSNumber {               status = AVPlayerItem.Status(rawValue: statusNumber.intValue)!               completionHandler?(self)     }           }
Posted Last updated
.