I'm interested in retrieving the current volume of a MediaPlayer, but don't see any method like 'getVolume()' on it. There is a setVolume(), so I'm a little confused as to why they don't also provide a way to read this property.
I saw some other answers that suggested to use AudioManager to read the volume:
int volumeLevel = am.getStreamVolume(AudioManager.STREAM_MUSIC);
int maxVolume = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
float volume = (float)volumeLevel/maxVolume;
However, this seems to return the device volume for all music, and not the volume that I'm setting with 'setVolume()'... is there a way to do get the volume directly from a MediaPlayer? I was thinking perhaps I need to do something with getAudioSessionId(). Thanks.
As far as I know this is not possible with the default MediaPlayer. You need to extend it and add your own getVolume() method along with a variable tracking the current volume.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With