Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you get/set media volume (not ringtone volume) in Android?

Is there a way to get/set media volume? I have tried the following:

AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE); int currentVolume = audio.getStreamVolume(AudioManager.STREAM_RING); 

but it returns the ringtone volume.

like image 738
Buda Gavril Avatar asked Jan 04 '11 12:01

Buda Gavril


People also ask

What is the difference between ringtone Volume and media Volume?

The ring and notification volume (Ringer volume icon) affects notifications, the in-call volume (In-call volume icon) affects calls and the media volume (Media volume icon) affects music, videos, games and other media. For example, if you change the volume while watching a video, the media volume is changed.

How do I separate ringtone and notification Volume Android?

The ringtone and notification sound volume can't be adjust separately as the Android operating system uses a single volume control for both. If you've increased the ringtone volume and the notification sound seems too loud for you, consider muting the notification sound. To mute the notification sound: Go to Settings.


1 Answers

private AudioManager audio; 

Inside onCreate:

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

Override onKeyDown:

@Override public boolean onKeyDown(int keyCode, KeyEvent event) {     switch (keyCode) {     case KeyEvent.KEYCODE_VOLUME_UP:         audio.adjustStreamVolume(AudioManager.STREAM_MUSIC,                 AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI);         return true;     case KeyEvent.KEYCODE_VOLUME_DOWN:         audio.adjustStreamVolume(AudioManager.STREAM_MUSIC,                 AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI);         return true;     default:         return false;     } } 
like image 188
Anthony Graglia Avatar answered Sep 24 '22 02:09

Anthony Graglia