gpt4 book ai didi

Android - 录制视频时将麦克风静音

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:10:49 29 4
gpt4 key购买 nike

在遵循与此类似的教程之后,我正在使用 MediaRecorder 类用相机录制视频

http://androidcookbook.com/Recipe.seam;jsessionid=40151FCD26222877E151C3EEFB406EED?recipeId=1375&recipeFrom=ViewTOC

而且我希望在录音时能够将麦克风静音/取消静音。这怎么可能?

我在开始时设置音频源

 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);
}

关于Android - 录制视频时将麦克风静音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41103030/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com