Can sound be turned off in MediaRecorder of the Android API?
I would like to write a program that records video but not sound.
Can an开发者_如何转开发yone help me on how to not record the sound while recording the video using MediaRecorder?
This is indeed possible. See the setAudioEncoder method in MediaRecorder:
If this method is not called, the output file will not contain an audio track.
So if you only want video, simply do not invoke this method.
You should just prepare your mediarecorder's video requirements, like:
private boolean prepareMediaRecorder(){
myCamera = getCameraInstance();
mediaRecorder = new MediaRecorder();
// store the quality profile required
CamcorderProfile profile = CamcorderProfile.get(mCameraId, CamcorderProfile.QUALITY_HIGH);
myCamera.unlock();
mediaRecorder.setCamera(myCamera);
mediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mediaRecorder.setOutputFormat(profile.fileFormat);
mediaRecorder.setVideoEncoder(profile.videoCodec);
mediaRecorder.setVideoEncodingBitRate(profile.videoBitRate);
mediaRecorder.setVideoFrameRate(profile.videoFrameRate);
mediaRecorder.setVideoSize(profile.videoFrameWidth, profile.videoFrameHeight);
mediaRecorder.setOutputFile("/sdcard/myvideo.mp4");
mediaRecorder.setMaxDuration(60000 * 20); // Set max duration 60 *20 sec.
mediaRecorder.setMaxFileSize(5000000 * 4); // Set max file size 5M * 4
mediaRecorder.setPreviewDisplay(myCameraSurfaceView.getHolder().getSurface());
try {
mediaRecorder.prepare();
} catch (IllegalStateException e) {
releaseMediaRecorder();
return false;
} catch (IOException e) {
releaseMediaRecorder();
return false;
}
return true;
}
精彩评论