zmxv / react-native-sound

React Native module for playing sound clips
MIT License
2.78k stars 747 forks source link

setCategory() mixWithOthers boolean does not work #815

Open kyrstencarlson opened 1 year ago

kyrstencarlson commented 1 year ago

:beetle: Description

The mix with others option on setCategory('Playback', true) does not work. It does not at all mix with sounds and causes all music playing in background (like spotify, apple music, etc) to completely stop when opening the app or the sounds from inside the app begin to play.

:beetle: What is the observed behavior?

see above

:beetle: What is the expected behavior?

sound plays over anything else playing, ie. mixing with others

:beetle: Please post your code:

Sound.setCategory('Playback', true);
Sound.setActive(true);
Sound.setMode('Default');

const finalBeep = new Sound('beep_single.mp3', Sound.MAIN_BUNDLE, error => {
    if (error) {
        return;
    }
});

//play function takes a boolean if the user marked sound being ON to return the sound being played.
play(finalBeep, context.isSoundOn);

:bulb: Does the problem have a test case?

:bulb: **Possible solution**

:bulb: Is there a workaround?

:bulb: If the bug is confirmed, would you be willing to create a pull request?

Is your issue with...

Are you using...

Which versions are you using?

Does the problem occur on...

If your problem is happening on a device, which device?

amberv0 commented 1 year ago

I'm facing the same issue (spent like 2 hours trying to find issue in react-native-video to finally realize that problem is not there). I'd like to add that playing the sound is not necessary to reproduce the issue, what causes the background music to stop is the new Sound(...) call.

amberv0 commented 1 year ago

Well, this issue seems to be a duplicate of this one, and the workaround provided there does work for me. One thing I noticed is that it's important to call Sound.setCategory('Playback', true); BEFORE new Sound(...). It was not the case for my app, and so I thought that the workaround didn't work.

BraveEvidence commented 1 year ago

This will help https://www.youtube.com/watch?v=vVI7ZAZq5e0