我正在使用MediaRecorder类录制与相机的视频,然后按照类似的教程
而我想在录音时能够使麦克风静音/取消静音.
怎么可能?
我正在开始设置音频源
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER); mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
但是,如果我想在某些时候没有声音录制呢?
解决方法
尝试以下代码:
private void setMicMuted(boolean state){ AudioManager myAudioManager = (AudioManager)mContext.getSystemService(Context.AUdio_SERVICE); // get the working mode and keep it int workingAudioMode = myAudioManager.getMode(); myAudioManager.setMode(AudioManager.MODE_IN_COMMUNICATION); // change mic state only if needed if (myAudioManager.isMicrophoneMute() != state) { myAudioManager.setMicrophoneMute(state); } // set back the original working mode myAudioManager.setMode(workingAudioMode); }