Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Playing sound stops background music on Android #133

Open
mrgzi opened this issue Feb 5, 2024 · 5 comments
Open

Playing sound stops background music on Android #133

mrgzi opened this issue Feb 5, 2024 · 5 comments

Comments

@mrgzi
Copy link

mrgzi commented Feb 5, 2024

One of my user reported me that everytime playing sound cause stop background music on Android.

Device: HUAWEI Y7 2019
Android version: 8.1 (SDK 27)

@am2074
Copy link

am2074 commented Apr 9, 2024

I don't have the solution but I did notice that it occurs (in ios as well) when:

Soundpool audioPool = Soundpool.fromOptions(); 
  
someSoundId = await rootBundle
     .load('assets/audio/someSound.mp3')
      .then((ByteData soundData) {
     return audioPool!.load(soundData);
    });

@iamnabink
Copy link

any solutions so far?

@donnfelker
Copy link

You need to use an Audio session to duck the audio. Here's a sample repo on how to do it: https://github.com/donnfelker/flutter-audio-ducking

@taosimple
Copy link

Use StreamType.notification

Soundpool.fromOptions(options: const SoundpoolOptions(
  streamType: StreamType.notification,
  iosOptions: SoundpoolOptionsIos(
    audioSessionCategory: AudioSessionCategory.ambient,
  ),
))

@burekas7
Copy link

burekas7 commented Dec 5, 2024

Any new about it?

When music is playing in the background on Android, it stops when the app loads.
Is the solution just to switch to a different package?

@taosimple
You solution doesn't work, it's the same.
also for "StreamType.alarm"

This code only solve it on iOS

    SoundpoolOptions _soundPoolOptions = SoundpoolOptions(
      streamType: StreamType.alarm,
      androidOptions: SoundpoolOptionsAndroid(),
      iosOptions: SoundpoolOptionsIos(
        audioSessionMode: AudioSessionMode.spokenAudio,
        audioSessionCategory: AudioSessionCategory.ambient,
      ),
    );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants