ryanheise / audio_session

MIT License
107 stars 68 forks source link

AVAudioSessionCategoryOptions.mixWithOthers stops background music the first time when audio is player, after continuing the music further sounds no longer stop the music #112

Closed JonasJW closed 8 months ago

JonasJW commented 8 months ago

My app plays sounds such as timers. It should not pause or duck any background music. I use the following config for it

AudioSession.instance.then((session) async {
  await session.configure(AudioSessionConfiguration(
    avAudioSessionCategory: AVAudioSessionCategory.ambient,
    avAudioSessionCategoryOptions: AVAudioSessionCategoryOptions.mixWithOthers,
    avAudioSessionMode: AVAudioSessionMode.defaultMode,
    avAudioSessionRouteSharingPolicy: AVAudioSessionRouteSharingPolicy.defaultPolicy,
    avAudioSessionSetActiveOptions: AVAudioSessionSetActiveOptions.none,
    // ANDROID
    androidAudioAttributes: const AndroidAudioAttributes(
      contentType: AndroidAudioContentType.sonification,
      flags: AndroidAudioFlags.none,
      usage: AndroidAudioUsage.game,
    ),
    androidAudioFocusGainType: AndroidAudioFocusGainType.gain,
    androidWillPauseWhenDucked: false,
  ));

  await session.setActive(true);

  // Init audio players...
});

For some reason, my app pauses the background music once when I play the first audio. If I continue the music, go back in my app, and play other sounds, it no longer pauses the music.

Any ideas on how I can resolve this?

ryanheise commented 8 months ago

Unfortunately I can't provide guidance on how to use the APIs, but you can instead try asking on StackOverflow. I think this question has probably come up before. Note that you might have more success searching for general iOS questions rather than flutter-specific questions.