Set the volume to maximum in Android

In my application, I am trying to set the volume when playing an audio clip to the maximum level, but it does not seem to affect. I have to manually adjust the volume to the maximum level. Here is my code:

MediaPlayer mp = new MediaPlayer(); mp.setVolume(1, 1); 
+4
source share
3 answers

Audiomanager

 int origionalVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC); mAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC), 0); 
+9
source

Use it

for total

 AudioManager mgr = (AudioManager) appContext.getSystemService(Context.AUDIO_SERVICE); int valuess = 9;//range(0-15) mgr.setStreamVolume(AudioManager.STREAM_MUSIC, valuess, 0); 

this is for left to right when the current song is playing ...

 AudioTrack m = (AudioTrack) appContext.getSystemService(Context.AUDIO_SERVICE); m.setStereoVolume(leftVolume, rightVolume); 

he works for me.

+4
source

Using AudioManager you can control the volume of the media player.

 AudioManager audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE); audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, 20, 0); 

also from MediaPlayer

 public void setVolume (float leftVolume, float rightVolume) 

for example, you can use this method as,

 int maxVolume = 100; float log1=(float)(Math.log(maxVolume-currVolume)/Math.log(maxVolume)); mp.setVolume(1-log1); 
+1
source

All Articles