MediaRecorder.OutputFormat.MPEG_4```
``` setAudioEncoder() - Set the sound encoding type, specify the default setting or
MediaRecorder.AudioEncoder.AMR_NB```
``` setVideoEncoder() - Set the video encoding type, specify the default setting or
MediaRecorder.VideoEncoder.MPEG_4_SP.```
setOutoutFile() Set the output file, use getOutputMediaFile(MEDIA_TYPE_VIDEO).toString() from
the example method in the Saving Media Files section.
setPreviewDisplay() - Specify the SurfaceView preview layout element for your application. Use
the same object you specified for Connect Preview.
Prepare MediaRecorder - Prepare the MediaRecorder with provided configuration settings by
calling MediaRecorder.prepare().
Start MediaRecorder - Start recording video by calling MediaRecorder.start().
Stop Recording Video - Call the following methods in order, to successfully complete a video recording:
Stop MediaRecorder - Stop recording video by calling MediaRecorder.stop().
Reset MediaRecorder - Optionally, remove the configuration settings from the recorder by calling
MediaRecorder.reset().
Release MediaRecorder - Release the MediaRecorder by calling MediaRecorder.release().
Lock the Camera - Lock the camera so that future MediaRecorder sessions can use it by calling
Camera.lock(). Starting with Android 4.0 (API level 14), this call is not required unless the
MediaRecorder.prepare() call fails.
Stop the Preview - When your activity has finished using the camera, stop the preview using Camera.stopPreview().
Release Camera - Release the camera so that other applications can use it by calling Camera.release().
在安卓中要想捕获视频需要小心的管理Camera对象和MediaRecorder的关系。当使用Camera录像时,除了调用open()和release()方法外,你还需要管理Camera.lock()和Camera.unlock()的调用,然后允许MediaRecorder去拿到Camera硬件。
相比于拍照,录像需要特定的调用顺序。如下:
打开相机 使用 Camera.open()获取camera实例
链接预览的View Camera.setPreviewDisplay()
开始预览 Camera.startPreview()
开始录像
Stop Recording Video - Call the following methods in order, to successfully complete a video recording:
Stop MediaRecorder - Stop recording video by calling MediaRecorder.stop().
Reset MediaRecorder - Optionally, remove the configuration settings from the recorder by calling MediaRecorder.reset().
Release MediaRecorder - Release the MediaRecorder by calling MediaRecorder.release().
Lock the Camera - Lock the camera so that future MediaRecorder sessions can use it by calling Camera.lock(). Starting with Android 4.0 (API level 14), this call is not required unless the MediaRecorder.prepare() call fails.
Stop the Preview - When your activity has finished using the camera, stop the preview using Camera.stopPreview().
Release Camera - Release the camera so that other applications can use it by calling Camera.release().