Android Mediarecorder录制的时候屏蔽掉声音
项目需求,在拍摄音视频时候将声音屏蔽,找了有关方面的资料,现总结下:
一、在原有工程中使用如下代码:
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
if (SettingsUtils.SETTINGS_SHOW_VOICE_SWITCH == 0){
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
}else{
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.VOICE_UPLINK);
}
if (DrivingRecorderUtil.CURSDKVERSION >= 8) {
CamcorderProfile targetProfile = CamcorderProfile
.get(CamcorderProfile.QUALITY_HIGH);
mMediaRecorder.setProfile(targetProfile);
} else {
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
}
mMediaRecorder.setVideoSize(SettingsUtils.SETTINGS_SHOW_FRAME[0],SettingsUtils.SETTINGS_SHOW_FRAME[1]);
原因CamcorderProfile 设置不仅仅是分辨率,它还将设置的东西作为输出格式和编码器 (用于音频和视频),所以放弃此方法使用。
二、修改代码如下:
//start实现录像静音
/*mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mMediaRecorder.setVideoSize(SettingsUtils.SETTINGS_SHOW_FRAME[0],