4 Replies
      Latest reply on Aug 13, 2019 2:20 PM by gtufano
      gtufano Level 1 Level 1 (0 points)

        I have a working application that uses multiple AVPlayer to play audio, each player holds a song and I play() another AVPlayer to play the next song (this is to allow realtime mixing between the 2 songs).

        The application works perfectly in foreground and background, unless the audio output is an AirPlay 2 speaker (I'm using a _new_ appleTV).

        If the output is AirPlay 2, as soon the app goes in background (or the song changes, changing AVPlayer), audio stops and the app is apparently stopped (It do not listen anymore to notification observations and the such). As soon as I move the app in foreground the pending notifications and observation starts. The stop happens ca. 80% of the times, it's not every time, but frequently enough.

        I tried anything I could imagine: Audio Session is now set to: [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback mode:AVAudioSessionModeDefault routeSharingPolicy:AVAudioSessionRouteSharingPolicyLongForm options:0 error:&error] (in case the route sharing policy interferes with everything) and set active. I also implemented AVRoutePickerView instead ov MPVolumeView as audio picker, just in case... and I also tried AVAudioSessionModeMoviePlayback mode (this is a sign I'm going into the magic realm).

        This is something related to AirPlay 2, because the application works in any other audio output context.

        Any hint/help will be appreciated, this is really frustrating.