Android MediaPlayer ignores it's internal volume when the system volume changes
- by Daniel Flower
Hi, here is my situation:
I have a media player playing music in an Android application. I've found that with certain headphones, the volume is much too loud even when the volume is set to it's lowest setting. As a result, I want to change the volume of the music for all volume levels to be 10% of what it normally is (actually, this value is user-defined of course).
The following works perfectly:
mediaPlayer.setVolume(0.1f, 0.1f);
The volume of the music is now at a good level for listening. However, if the user now changes the volume using the volume rocker (thus changing the music stream volume), the media player changes the volume as expected, but it also seems to reset the 'setVolume' parameters to 1.0, causing a massive volume change. Setting the volume back to 0.1 sets the volume to how it should be (which is 10% of the current music stream volume).
To quote the Android docs for the MediaPlayer.setVolume method:
This API is recommended for balancing the output of audio streams within an application
How can you do this if it gets reset to 1.0 each time the system volume changes?
Any help muchly appreciated. Thanks.