0

I was trying to use MediaPlayer and AudioManager to change the volume of an audio file using app buttons. I seem to have messed up my emulator. The volume setting of the emulator and of my speakers is maxed but I can barely hear the sound file. Audio from other applications are working normally. I tried clearing the data from the emulator but that had no effect. Is there some way to reset the volume settings? I was using the following suggestions from other posts.

AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE);
int currVolume= am.getStreamVolume(AudioManager.STREAM_MUSIC);
currVolume++; // to change the volume
int maxVolume = 50;
float log1=(float)(Math.log(maxVolume-currVolume)/Math.log(maxVolume));
yourMediaPlayer.setVolume(1f-log1, 1f-log1);

Every time I executed this code on the emulator, the volume got lower and I can't bring it back up, no matter what I put in .setVolume()

Pang
  • 9,564
  • 146
  • 81
  • 122
C. Thomson
  • 13
  • 5

1 Answers1

0

The following has brought the volume back up. The currentVolume was 3 whereas the maxVolume is 15. I'm still not sure how mediaPlayer.setVolume() works.

AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
int currentVolume = audio.getStreamVolume(AudioManager.STREAM_MUSIC);
int maxVolume = audio.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
audio.setStreamVolume(AudioManager.STREAM_MUSIC, maxVolume, 0);
Pang
  • 9,564
  • 146
  • 81
  • 122
C. Thomson
  • 13
  • 5