Audio tracks cut in offline mode

Hi !

I’m running my app under Ionic 5.4 + Vue and a custom audio player plugin in swift.
I’m using the swift capacitor plugin that allows the user to :

  • Play, pause and seek the audio track (uses AVPlayer)
  • Download an audio track
  • Once downloaded, listen to the audio track in offline mode

My issue : In offline mode, the audio track will cut at a seemingly random time without errors.

It doesn’t matter if the track is very long or very short (heavy or lightweight) :

  • For example a 58min-long track can cut at 6min or 20min in offline mode.
  • A 5min-long track can sometimes cut at 52 seconds.

If you press the play button after that unexpected stop, the track will play again for a few minutes and stop again.
What’s even weirder is that when the phone is locked, the CommandCenter seekbar will continue to play even when the track has stopped in-app.
This only happens when emulating on a physical device but not on an Xcode Simulator.

Further information :

  • In the config.xml file, the APPBackgroundMode is set to true
  • In the Info.plist file, the UIBackgroundModes is enabled with the « audio » string
  • ionic BackgroundMode plugin is enabled

Despite trying to catch an error in the swift custom plugin, no error is returned in Xcode when the track stops playing. I am running out of ideas on how to debug this since I can’t seem to get an error.

Do you have any idea to suggest to me to fix this problem ?

Thank you !

1 Like