android 调节媒体音量
作者:互联网
原文链接:http://www.cnblogs.com/tracydj/archive/2011/11/02/2232640.html
引用 AudioManager 对象
AudioManager audio = (AudioManager) getSystemService(Service.AUDIO_SERVICE);
重写 Activity 的 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_PLAY_SOUND | AudioManager.FLAG_SHOW_UI);
return true;
case KeyEvent.KEYCODE_VOLUME_DOWN:
audio.adjustStreamVolume(
AudioManager.STREAM_MUSIC,
AudioManager.ADJUST_LOWER,
AudioManager.FLAG_PLAY_SOUND | AudioManager.FLAG_SHOW_UI);
return true;
default:
break;
}
return super.onKeyDown(keyCode, event);
}
转载于:https://www.cnblogs.com/tracydj/archive/2011/11/02/2232640.html
标签:return,AudioManager,调节,KeyEvent,onKeyDown,FLAG,音量,android,audio 来源: https://blog.csdn.net/weixin_30448685/article/details/97825523