zmxv / react-native-sound

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

Play sound file with constant volume, independent of user settings #611

Open mronline opened 5 years ago

mronline commented 5 years ago

:clipboard: Description

Is there any way in iOS to keep playing a sound file at a constant sound volume? So no matter if the user did set the ringtone of his phone to very low volume, I still want to play my audio file at the same volume as if the phone was set to loud. Kind of like what Siri does. She's also independent of every other sound-volume setting.

Thanks

paulmelnikow commented 5 years ago

No, I don't think this is possible in iOS! If you find any resources that suggest otherwise, please post them!

mronline commented 5 years ago

I found these: https://github.com/pohsiu/react-native-ios-volume https://github.com/c19354837/react-native-system-setting

paulmelnikow commented 5 years ago

Haven't tried that, though if it works, seems like it's not exactly what you're asking for but a workaround.

mronline commented 5 years ago

I tried to do it this way, but it doesn't work very well:

soundPlayer.getSystemVolume((volume) => {
        soundPlayer.setVolume(Math.pow(1 / volume, 2));
        soundPlayer.play();
    });

https://stackoverflow.com/questions/35842837/ios-play-sound-file-with-constant-volume-independent-of-user-settings

Just const the sound of the device that comes to mind. :)