3 Replies
      Latest reply on Apr 15, 2020 11:21 AM by lukkasperek
      lukkasperek Level 1 Level 1 (0 points)

        I'm having an issue with playing sequences of different kinds of items in a background.

        In an app I'm working on we've introduced playlists which contain both content provided by the app and Apple Music content.

        For that use AVPlayer and MPMusicPlayerController respectively. We observe one player or the other (depending what content is now playing) and if the other kind of content comes next, we release the old player (if we can - MPMusicPlayerController is a singleton, so best we can do is stop it) and load item to another player.

        The problem starts when the app leaves foreground. Once MPMusicPlayerController takes over it doesn't want to give up control, so if any AVPlayer content comes after MPMusicPlayerController content, the music stops.


        One workaround that I've tried is playing with `.mixWithOthers` options when I set the category on AVAudioSession, however this creates new category of problems - I'm loosing lockscreen controls, therefore I'm also loosing airplay. One dirty trick that I've tried was setting `.mixWithOthers` 3 seconds before MPMediaItem ends, and then disabling it back once AVPlayer starts. Beside the fact that there're probably many different things that can go wrong here, MPMediaPlayerController still doesn't want to give me back the control over lockscreen controls.


        Is there any way this could ever work on iOS 13?