Skip to content

fix: Unexpected persistent ducking when combining flutter_soloud with audio_session #326

@koenhagen

Description

@koenhagen

Description

When using flutter_soloud together with audio_session, background audio (like Spotify) gets ducked continuously after activating the session, even when no sound is playing. I want to play short sounds occasionally and have other audio duck only during playback, similar to how apps like Strava or Google Maps behave.

Steps To Reproduce

  1. Play audio in other app (e.g. Spotify)
  2. Set up audio_session with
AudioSessionConfiguration(
          androidWillPauseWhenDucked: true,
          androidAudioAttributes: AndroidAudioAttributes(
            usage: AndroidAudioUsage.assistanceNavigationGuidance,
            contentType: AndroidAudioContentType.speech,
          ),
          androidAudioFocusGainType:
          AndroidAudioFocusGainType.gainTransientMayDuck,
          avAudioSessionCategory: AVAudioSessionCategory.playback,
          avAudioSessionCategoryOptions: AVAudioSessionCategoryOptions.duckOthers,
          avAudioSessionMode: AVAudioSessionMode.spokenAudio,
        )
  1. Observe that background audio is ducked on app startup
  2. Activate the session with setActive(true)
  3. Play a sound using flutter_soloud
  4. Observe that background audio remains ducked even after playback ends

Expected Behavior

Background audio should duck only during playback and return to normal once the sound finishes.

Additional Context

Tested on iOS with both flutter_soloud 3.3.4 and 3.1.12 (before audio_session support was introduced). I followed the example from audio_context.dart while changing the configuration. The goal is to play occasional sounds while respecting other audio sources.

I haven't tested the later versions of flutter_soloud on Android yet. I recall not having this issue there, but this presumably was before v3.2.1. That may or may not mean that behaviour differs depending on the device (or my configuration differs). Though I do not have an Android device to test this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions