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):
systemMusicPlayer
completely and using AVAudioPlayer
with the Apple Music API (this would be reinventing the wheel a little bit and would force streaming even if the media was downloaded)applicationQueuePlayer
and just forcing the user to stay in app (this would be a bad user experience imo, they should be able to listen in the background)Any help would be appreciated, thank you!
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