Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to increase volume of mediaPlayer

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.

like image 967
Ali Behzadian Nejad Avatar asked Dec 16 '22 00:12

Ali Behzadian Nejad


1 Answers

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);
like image 186
kapandron Avatar answered Dec 18 '22 14:12

kapandron