Can I change the media volume? and how? I used this so far:
setVolumeControlStream(AudioManager.STREAM_MUSIC);
But have a seekbar and want to change the media volume, not ring volume.
So can someone show me how to just change the media volume at onCreate()
and I fix the seekbar later.
Use
adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE, flags);
http://developer.android.com/reference/android/media/AudioManager.html#adjustStreamVolume(int, int, int)
The right method to use would be setStreamVolume on your
AudioManager
. It could looks like thisAn example use of the flag is to get the beep when setting the volume so the user can hear the outcome. The flag for that would be
AudioManager.FLAG_PLAY_SOUND
.You could use
AudioManager.FLAG_SHOW_UI
if you don't want to play a sound but display a toast with the current value. The use has to get a feedback tho. Doesn't matter if it is audible or visual.To get the maximal valid value for the given stream you just call
getStreamMaxVolume()
on theAudioManager
and get an integer back which represents ... well the maximal valid value for the volume.Inside onCreate:
Override onKeyDown:
Giving a 0 - in the flags avoids getting a visual and audio indicator . That's good when you implement your own audio bar and indicator and you don't want android to add anything.
You can use the following code to handle Volume using a SeekBar: