zmxv / react-native-sound

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

setVolume doesn't work when phone volume is low #599

Closed Ilario17 closed 5 years ago

Ilario17 commented 5 years ago
Sound.setCategory('Playback');

let alarmSound = new Sound('popcorn.aif', Sound.MAIN_BUNDLE, (error) => {
    if (error) {
        console.log(error); 
    } else {
        alarmSound.setVolume(0.1);
        alarmSound.setPan(1);   
    }
})

I tried setVolume(1) and nothing has changed.

The sound starts but if the phone has the minimum volume setVolume does not affect. I would like to have the possibility to play the sound even if the user set the phone volume to 0

react-native-sound version: 0.11.0 react-native version: 0.58.4

tested on iPhone XR iOS 12.2

paulmelnikow commented 5 years ago

Hi! Thanks for the report.

The sound starts but if the phone has the minimum volume setVolume does not affect. I would like to have the possibility to play the sound even if the user set the phone volume to 0

This is the expected behavior of setVolume().

There is a setSystemVolume() function on Android but on iOS there is only getSystemVolume(). Out of curiosity, can you see what that returns?

From some searching, it looks like MPVolumeView is the way to set system volume on iOS.

Some possible solutions for React Native:

Ilario17 commented 5 years ago

Thank you for your answer, I'll try the libraries listed

setVolume is therefore used to set the volume of the audio and not that of the phone, right?

paulmelnikow commented 5 years ago

setVolume is therefore used to set the volume of the audio and not that of the phone, right?

Yes, on iOS according to the docs:

Use this property to control an audio player’s volume relative to other audio output.

I'd really welcome a pull request to add that to the readme! Could probably be a couple sentences in the code sample.