Search code examples
iosobjective-cavfoundationavplayer

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?


Solution

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