I'm recording a video with the camera, using the MediaRecorder class, after following a tutorial similiar to this
And I want while recording, to be able to mute / unmute the microphone. How's that possible?
I'm setting the audio source at start
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
But what if I want to record without sound at some point?
Try the following code:
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);
}