0

My iOS app uses the MPMusicPlayerController.applicationMusicPlayer to play music and it can also play other sounds via AVAudioPlayer simultaneously.

It works fine playing through either the device speakers or bluetooth earphones / headsets.

When it comes to AirPlay to devices like Apple TV or HomePod, the music is sent but the AVAudioPlayer stuff remains on the device. I want everything over AirPlay!

Note: the audio session is initialized like so:

try? AVAudioSession.sharedInstance().setCategory(.playback, mode: .default, options: [.allowAirPlay, .mixWithOthers])

I cannot use the longForm policy because that would stop the music. I've tried different things here but no luck so far.

Germán
  • 4,525
  • 3
  • 31
  • 37
  • 1
    First, remove the `?` in `try?`. You're throwing away any errors that the system provides you. For example, your `options` are not valid. The docs note that `allowAirPlay` "can only explicitly set this option if the audio session’s category is set to playAndRecord." So it's possible this `setCategory` is not used. `mixWithOthers` refers to "your app mixes its audio with audio playing in background apps, such as the Music app" (which is not `applicationMusicPlayer`). It is possible these mistakes don't matter; but you won't know if you throw away the errors. – Rob Napier Aug 02 '22 at 20:53
  • 1
    @RobNapier you're absolutely right and I'm glad I posted that line. It throws. Setting no options seems to do the trick! – Germán Aug 02 '22 at 21:59

0 Answers0