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.
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.
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.
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; } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With