abhi
abhi

Reputation: 154

Increase MediaPlayer volume beyond 100%

Below code is working but not increasing the media player volume higher than the default max volume.Please help

AudioManager am = 
    (AudioManager) getSystemService(Context.AUDIO_SERVICE);

am.setStreamVolume(
    AudioManager.STREAM_MUSIC,
    am.getStreamMaxVolume(AudioManager.STREAM_MUSIC),
    0);

Upvotes: 1

Views: 2768

Answers (2)

derat
derat

Reputation: 217

The MediaPlayer class's setVolume() method only accepts scalars in the range [0.0, 1.0], but the classes deriving from AudioEffect can be used to amplify the MediaPlayer's audio session.

For example, LoudnessEnhancer amplifies samples by a gain specified in millibels (i.e. hundredths of decibels):

MediaPlayer player = new MediaPlayer();
player.setDataSource("https://www.example.org/song.mp3");
player.prepare();

// Increase amplitude by 20%.
double audioPct = 1.2;
int gainmB = (int) Math.round(Math.log10(audioPct) * 2000);
LoudnessEnhancer enhancer = new LoudnessEnhancer(player.getAudioSessionId());
enhancer.setTargetGain(gainmB);

It's unclear from the documentation, but it appeared to me that LoudnessEnhancer doesn't work properly with negative gains, so you may still need to use MediaPlayer's setVolume() method if you want to decrease the volume.

DynamicsProcessing provides multiple stages across multiple channels, including an input gain stage.

Upvotes: 7

Arun Antoney
Arun Antoney

Reputation: 4382

For increasing the volume of the device beyond the system volume u have to go in engineers mode.for that save below code.and paste it in number entering box In calling option it will directly redirect you to the engineers mode

      *#*#3646633#*#*

By this you can access the system settings one thing make sure that don't use this without care it may affect your system performance.

Upvotes: 0

Related Questions