Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AVPlayer and AVFoundationErrorDomain Code=-11819

i am developing an app where the music is played via AVPlayer using songs from a cloud service. everything works fine and most of the files are playing without any issues.

i have recently been getting an error back from specific files and with the message coming from AVPlayer i can't figure out if it's a network communication issue or the encoding of the file itself:

Error Domain=AVFoundationErrorDomain Code=-11819 "Cannot Complete Action" UserInfo=0x176abd80 {NSLocalizedRecoverySuggestion=Try again later., NSLocalizedDescription=Cannot Complete Action}

looking through the documentation I found out that code 11819 means:

AVErrorMediaServicesWereReset - The operation could not be completed because media services became unavailable.

has anyone ever experienced this before?

like image 535
Mavis Avatar asked Dec 14 '13 09:12

Mavis


People also ask

How do I resolve the avfoundationerrordomain-11819 error while watching an episode?

If you experience an AVFoundationErrorDomain-11819 error while watching an episode on your Apple TV or iOS device, you will need to refresh your device to clear the error. Please try the following steps to resolve the issue. Unplug your Apple TV as well as the TV it's connected to from power for a minimum of 2 minutes

What is the coremediaerrordomain code for avplayer?

Error Domain=CoreMediaErrorDomain Code=-12642 "Playlist parse error" (See - [AVPlayerItem errorLog] for 2 events) UserInfo= {NSDescription=Playlist parse error, NSDebugDescription=See - [AVPlayerItem errorLog] for 2 events}) AVPlayer will catch CoreMediaErrorDomain errors while playback video.

What are the error codes in avplayer?

When AVPlayer get these error codes, it exec the recovery below: 410, 500, 502, 503, 504: Switch other variants. iOS 11 catch temporary resource/server unavailability with EXT-X-GAP tag in Playlist. It is unverified I wish to Write this feature on next letter.

How to reactivate the avaudiosession instance when error -11819 occurs?

When appropriate, use the setActive: error: method to reactivate the AVAudioSession instance Error -11819 indicates that a helper process has crashed. Please report this using the feedback assistant and include a sysdiagnose so we can see what happened to that process.


2 Answers

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).

like image 152
Mavis Avatar answered Sep 25 '22 17:09

Mavis


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()
        }
    }
like image 42
David H Avatar answered Sep 25 '22 17:09

David H