多媒体音量调节的方法

/** * * [多媒体音量调节]
* [功能详细描述] * * @param keyCode * @param event * @return * @see android.app.Activity#onKeyDown(int, android.view.KeyEvent) */ @Override public boolean onKeyDown(int keyCode, KeyEvent event) { // TODO Auto-generated method stub if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) { AudioManager audioMa = (AudioManager) this .getSystemService(Context.AUDIO_SERVICE); audioMa.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE, AudioManager.FX_FOCUS_NAVIGATION_UP); return true; } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) { AudioManager audioMa = (AudioManager) this .getSystemService(Context.AUDIO_SERVICE); audioMa.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_LOWER, AudioManager.FX_FOCUS_NAVIGATION_UP); return true; } else { return super.onKeyDown(keyCode, event); } }

 

 

 

 

 

 

 

或者:  setVolumeControlStream(AudioManager.STREAM_MUSIC);

 

 

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

//通话音量

      int max = am.getStreamMaxVolume( AudioManager.STREAM_VOICE_CALL );

      int current = am.getStreamVolume( AudioManager.STREAM_VOICE_CALL );

      Log.d(”VIOCE_CALL”, “max : ” + max + ” current : ” + current);

//系统音量

      max = mAudioManager.getStreamMaxVolume( AudioManager.STREAM_SYSTEM );

      current = mAudioManager.getStreamVolume( AudioManager.STREAM_SYSTEM );

      Log.d(”SYSTEM”, “max : ” + max + ” current : ” + current);

//铃声音量

      max = mAudioManager.getStreamMaxVolume( AudioManager.STREAM_RING );

      current = mAudioManager.getStreamVolume( AudioManager.STREAM_RING );

      Log.d(”RING”, “max : ” + max + ” current : ” + current);

//音乐音量

      max = mAudioManager.getStreamMaxVolume( AudioManager.STREAM_MUSIC );

      current = mAudioManager.getStreamVolume( AudioManager.STREAM_MUSIC );

      Log.d(”MUSIC”, “max : ” + max + ” current : ” + current);

//提示声音音量

      max = am.getStreamMaxVolume( AudioManager.STREAM_ALARM );

      current = sm.getStreamVolume( AudioManager.STREAM_ALARM );

      Log.d(”ALARM”, “max : ” + max + ” current : ” + current);

设置音量的方法也很简单,AudioManager提供了方法:
public void setStreamVolume(int streamType, int index, int flags)
其中 streamType 有内置的常量,可以在AudioManager里面查到相关的定义。

你可能感兴趣的:(音频处理,Android)