AVPlayer and AVFoundationErrorDomain Code=-11819

I found the solution by using the following method before loading the AVURLAsset to AVPlayerItem

  • (void)loadValuesAsynchronouslyForKeys:(NSArray *)keys completionHandler:(void (^)(void))handler

The reason why it was crashing in specific tracks was because some of them where mp3 files and they don't have all the information about the song immediately available (e.g. duration).


As was stated, the keys are properties on AVAsset. Apple says in its docs that you should always use this in iOS (but I doubt its needed for file based videos).

I struggled with this, in the end it didn't matter - but in any case maybe this will help someone in the future:

    asset = AVAsset(url: videoURL)
    let keys = ["duration", "playable", "preferredRate", "preferredVolume", "hasProtectedContent", "providesPreciseDurationAndTiming", "metadata"]
        asset.loadValuesAsynchronously(forKeys: keys) {
        for key in keys {
            var error: NSError? = nil
            let status = self.asset.statusOfValue(forKey: key, error: &error)
            print("KEY:", key, terminator: "")
            switch status {
            case .loading:
                print("  Loading")
            case .loaded:
                print("  Sucessfully loaded, continue processing")
            case .failed:
                print("  Failed with error \(error!)")
            case .cancelled:
                print("  CANCELLED")
            case .unknown:
                print("  Unknown")
            default:
                print("  DEFAULT")
            }
        }
        print("WAIT A BIT...")
        DispatchQueue.main.async {
            print("...RUN IT")
            self.runMovie()
        }
    }