We have a React Native application that is using bitmovin-player-react-native to power our media playback capabilities. Recently we’ve been receiving a few The operation couldn’t be completed. (CoreMediaErrorDomain error 561210739.) errors in our app, but this issue doesn’t seem to be easily reproducible. Based on the OSStatus website (OSStatus — Apple API Errors), I believe this error code is related to the AVAudioSessionErrorCodeExpiredSession error in Apple’s documentation, AVAudioSessionErrorCodeExpiredSession | Apple Developer Documentation. This issue is only experienced on iOS devices.
I was curious if anyone had any experience with this error and what may be the root cause of it?
Unfortunately, the error messages from iOS are usually not very helpful. You said the issue is not easily reproducible. Does this mean you maybe have some hints on how it could be reproduced?
OSStatus could be a good hint but also not always super helpful (not all error codes can be found there). If it’s really related to the AVAudioSessionErrorCodeExpiredSession error, do you have any custom AVAudioSession handling in your App?
No, I do not actually have reproduction steps for this issue. I haven’t been able to reproduce it myself, but it is an error we have seen pop up several times in our production environment.
We did recently update our app code so that we can allow background playback. We integrated in react-native-track-player into the app so that we can pass metadata to this player. This is about the only change we added in as far as the code is concerned, I do not think this necessarily ties into AVAudioSession stuff – although the playback controls in the media player does have an effect on AVAudioSession.
Do I understand the use case correctly that you are using the bitmovin-player-react-native player for video playback and react-native-track-player for background playback and to get the playback controls e.g. on the lock screen?
I had a quick look at the react-native-track-player and the underlying SwiftAudioEx framework, and they do use the AVAudioSession, but I could not find anything which could conflict with our Bitmovin iOS Player.
One thing you could try is to remove or disable react-native-track-player to see if the problem still occurs to see which library might be at fault.
Another option you could try is to add this snippet to the screen where you have the player:
useEffect(() => {
// iOS audio session category must be set to `playback` first, otherwise playback
// will have no audio when the device is silenced.
// This is also required to make Picture in Picture work on iOS.
//
// Usually it's desireable to set the audio's category only once during your app's main component
// initialization. This way you can guarantee that your app's audio category is properly
// configured throughout the whole lifecycle of the application.
AudioSession.setCategory('playback').catch((error) => {
// Handle any native errors that might occur while setting the audio's category.
console.log("Failed to set app's audio category to `playback`:\n", error);
});
});
It is recommended to set the category of the AudioSession to enable background playback for bitmovin-player-react-native.
See this section of our PiP guide (the same setup is required for background playback as for picture in picture).