zmxv / react-native-sound

React Native module for playing sound clips
MIT License
2.79k stars 748 forks source link

setCategory() not working on Android #551

Open johanschram opened 5 years ago

johanschram commented 5 years ago

Hi,

I'm trying for my app to use sounds as user feedbacks (like a ping on sending a message). The idea is that if users are already listenign to music on some other back running on backgroud, it should stop the current music flow. I used setCategory('Ambiant'), which work perfectly fine on IOS, but doesn't seems to do anything on Android : when a sound is played, it stops the background music.

Here is my implementation :


import Sound from 'react-native-sound';

Sound.setCategory('Ambient');

let pop = new Sound('pop1.mp3', Sound.MAIN_BUNDLE, (error) => {if (error) {console.log('failed to load the sound', error);}});
let notif = new Sound('notif.mp3', Sound.MAIN_BUNDLE, (error) => {if (error) {console.log('failed to load the sound', error);}});

let soundLibrarie = {
    pop : pop,
    notif : notif
};

const play= (soundName)=>{
    if (soundLibrarie[soundName] !== undefined){
        soundLibrarie[soundName].play((success)=>{})
    }
};

export default { play }

To be honnest I don't know if this is a bug, or if this is related to my implementation ... Any ideas ?

Thanks !

React-native : 0.57.1 react-native-sound : 0.10.12

CyxouD commented 4 years ago

react-native-sound wiki states that it works only on iOS https://github.com/zmxv/react-native-sound/wiki/API#static-methods. However, I also want to control it on Android

avetisyan66 commented 1 year ago

Hey, I want to change the speaker of android from ear speaker to loud speaker. As the documentation says setCategory is not working on iOS. I also tried setSpeakerphoneOn method. It didn't do anything. Did anyone know how to change the output of the audio speaker using react-native-sound ?