How to increase volume of mediaPlayer

android, android-mediaplayer

Solution

This isn't the function for setting the volume. Here it's the setting of the volume to any value:

AudioManager audioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
// For example to set the volume of played media to maximum.
audioManager.setStreamVolume (AudioManager.STREAM_MUSIC, audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC),0);

Problem

I am writing an app that in some situations warns user with an alarm sound. My problem is that in some situation volume of media playing may be decreased by user or even media volume is silent. I want to check the volume programatically and increase it to 100% and then play alarm. Any idea? Note that I have tested `mediaPlayer.setVolume(1,1)` and nothing changed.

Original source