'Background multiple record videos service with MediaRecorder
I've used MediaRecorder in a background record video application. When record file is full, I change output file. When changing output file, I must stop MediaRecorder to prepare and start it again. But this make my preview Surface blink in a short of time. Is there any solution for this ?
Start
public void start() {
mMediaRecorder = new MediaRecorder();
mMediaRecorder.setCamera(mCamera);
mMediaRecorder.setPreviewDisplay(mSurfaceView.getHolder().getSurface());
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
mMediaRecorder.setVideoEncoder(MediaRecorder.VideoEncoder.H264);
mMediaRecorder.setVideoEncodingBitRate(256 * 10000); //2,560kb/s
mMediaRecorder.setVideoFrameRate(30);
mMediaRecorder.setVideoSize(CameraView.PREVIEW_WIDTH, CameraView.PREVIEW_HEIGHT);
String fileName = mCommon.dateFormat("yyyyMMdd-HHmm", null) + ".mp4";
File file = createInternalOutput(fileName);
mMediaRecorder.setOutputFile(file.getPath());
mMediaRecorder.setOnInfoListener(this);
mMediaRecorder.setMaxFileSize(VIDEO_FILESIZE);
mMediaRecorder.setMaxDuration(VIDEO_DURATION);
try {
mMediaRecorder.prepare();
mMediaRecorder.start();
} catch (IOException e) {
e.printStackTrace();
}
}
On Info
public void onInfo(MediaRecorder mr, int what, int extra) {
if (what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_DURATION_REACHED || what == MediaRecorder.MEDIA_RECORDER_INFO_MAX_FILESIZE_APPROACHING) {
boolean detectRecording = mCommon.getSettings(MainActivity.DETECT_RECORDING, false);
stopRecord();
start();
}
}
Stop
public void stopRecord() {
mMediaRecorder.stop();
mCamera.unlock();
isRecording = false;
}
Updated: I've found it. Because the size of preview surface and Layout in service is not the same. The answer is here [question]: Screens flickers and resizes when starting video recording
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
