iosswiftavaudioplayerapple-musicapple-musickit

Background Audio mode with MPMusicPlayerController.systemMusicPlayer


I'm working on an iOS app that uses MPMusicPlayerController.systemMusicPlayer to play songs from Apple Music to the user.

My app should be able to append songs to the Music player's queue based on messages it receives from a server. I have this working with a simple WebSocket connection between the app and the server, but as soon as the app enters the background the socket is automatically closed (which makes sense).

Because the actual music playback is done by the Music app, I can't use the Background Audio background mode to keep my app alive. Is there a way around this?

Things I have already considered (and why I don't think they will work):

Any help would be appreciated, thank you!


Solution

  • In iOS 15 and later, you should be able to just set the background plist flag for your app, and then just use ApplicationMusicPlayer.

    https://developer.apple.com/documentation/musickit/applicationmusicplayer