3
votes

Our team have an app to play back m4a resources online using the avplayer. Recently, there are some users complaining the playback is keep failing and we have no idea the reason behind this.

We checked the user log and the avplayer error log are as follow (for multiple failed instance):

  • avPlayer.currentItem.error = Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSLocalizedFailureReason=An unknown error occurred (-16155), NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x280e6ef10 {Error Domain=NSOSStatusErrorDomain Code=-16155 "(null)"}}
  • avPlayer.currentItem.error = Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSLocalizedFailureReason=An unknown error occurred (606068440), NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x280e9f8d0 {Error Domain=NSOSStatusErrorDomain Code=606068440 "(null)"}}
  • avPlayer.currentItem.error = Error Domain=AVFoundationErrorDomain Code=-11800 "The operation could not be completed" UserInfo={NSLocalizedFailureReason=An unknown error occurred (1705376704), NSLocalizedDescription=The operation could not be completed, NSUnderlyingError=0x281ec60d0 {Error Domain=NSOSStatusErrorDomain Code=1705376704 "(null)"}}

The normal flow for us to start playing: (Work as expected for majority of user)

  1. [[AVAudioSession sharedInstance] setActive:YES error:&activationError];
  2. call [avplayer play]
  3. the audio started to play successfully

Failed scenario: (For some users, this scenario keeps happening)

  1. The activation error returns Error Domain=NSOSStatusErrorDomain Code=2003329396 "(null)"
  2. We logged the [AVAudioSession sharedInstance].category becomes empty
  3. The mediaServicesWereReset notification is received
  4. the avplayer failed to play and the one of the above avplayer item error is observed

When the user failed once, he cannot play any audio resources in our app and the scenario is keep repeating.

We would like to know:

  1. Why would this occur on certain user devices?
  2. How to prevent the problem occurs?
  3. Is there a way to recover from the lost mediaService? so that even if the error occurs once, the user can still play other resources in our app.

We cannot produce the fail scenario by ourselves even we tried the Reset Media Services in developer menu, the behaviour is not exactly the same. Look forward to any help from the community and thanks.

1
Have you been able to solve this issue? - Arda

1 Answers

2
votes

I can't answer your first two questions with certainty, but Apple's answer to your last question is as follows:

Upon receiving the AVAudioSessionMediaServicesWereResetNotification notification, applications should:

  • Dispose orphaned audio objects and create new audio objects
  • Reset any internal audio state being tracked, including all properties of AVAudioSession
  • When appropriate, reactivate the AVAudioSession using the setActive:error: method

See https://developer.apple.com/library/archive/qa/qa1749/_index.html for more information on this.

As for my guesses for your first two questions:

  1. The problem may not be specific to certain user devices, but may rather be somewhat random. I've been seeing a similar, very rare problem in Apple provided crash logs from customer devices, which I could never reproduce until today. Now I'm finally able to reproduce the problem by simply repeating the normal operations of the app thousands of times in an automatic test. Very rarely, iOS resets the Audio Session Media Services, and causes either the session activation or deactivation to fail. In this case, restarting the Audio Session after some delay seems to solve the problem. (I'm still testing though, as each test takes several hours before I can reproduce the problem).
  2. Considering Apple's technical note I've linked above doesn't provide any indication that a reset of the Audio Session Media Services could be avoided, I'm guessing there may not be a way to reliably prevent it from happening. The less frequently (or the fewer times) you activate/deactivate the audio session, the less likely it might be for this issue to occur, but eventually it may still occur for some arbitrary users. That's why the right thing to do would be to assume that AVAudioSessionMediaServicesWereResetNotification is sometimes unavoidable, and therefore handle it as outlined above.