1

I use android.media.MediaPlayer to play some sounds in my app, but when i press the physical volume button, it only changes the system volume (ringtone volume). I searched in google but i haven't had any idea yet. I use android.media.MediaPlayer not Audiomanger.

1 Answers1

1

Call the following right before you start playing music

setVolumeControlStream(AudioManager.STREAM_MUSIC);

and call the following after you finish

setVolumeControlStream(AudioManager.USE_DEFAULT_STREAM_TYPE);

This makes your volume rocker control all music streams and then resets it to default behavior (depends on what's happening).

Don't forget to call myMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC) before myMediaPlayer.prepare(). Replace STREAM_MUSIC in both calls with some other value if it fits the played sound better. This makes the music you play conform to the music volume set in system, which is now controlled by the volume rocker.

Source:

http://developer.android.com/training/managing-audio/volume-playback.html

http://developer.android.com/reference/android/media/MediaPlayer.html#setAudioStreamType(int)

Eugen Pechanec
  • 37,669
  • 7
  • 103
  • 124