zmxv / react-native-sound

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

how to set the independent audio volume? #737

Open luigbren opened 2 years ago

luigbren commented 2 years ago

:beetle: Description

how to set the audio volume independent of the operating system??

Hi, I have a problem, how can I adjust the volume of the sound that is played independently to the audio of the OS?

I usually have on my mobile phone the multimedia audio volume at 0% (I turn up the audio volume when I want to listen to a video)....

In my chat application when I receive a message, the sound is reproduced without problems but on my phone is not hear the sound because the multimedia audio on my phone I have it 0%, example: if I get a WhatsApp message I hear the sound at 100%

How can I do the same?, I tried with the command .setVolume but I have no results.

var audio = new Sound('msg.mp3', Sound.MAIN_BUNDLE, error => {
              if (error) {
                console.log('failed to load the sound', error);
                return;
              }
              audio.play(success => {
                if (success) {
                  //console.log('successfully finished playing');
                } else {
                  //console.log('playback failed due to audio decoding errors');
                }
              });
            });
            audio.setVolume(0.5); // setVolume(1), setVolume(100) and nothing happens, dont listen the sound

            audio.stop(() => {
              // Note: If you want to play a sound after stopping and rewinding it,
              // it is important to call play() in a callback.
              audio.play();
            });
            audio.release();

Is your issue with...

Are you using...

Which versions are you using?

Does the problem occur on...