<video controls>
<source src="hogehoge.mp4" type="video/webm">
<source src="hogehoge.mp4" type="video/mp4">
I'm sorry; your browser doesn't support HTML5 video in WebM with VP8 or MP4 with H.264.
</video>
>Set the video output format and encoding. For Android 2.2 (API Level 8) and higher, use the MediaRecorder.setProfile method, and get a profile instance using CamcorderProfile.get(). For versions of Android prior to 2.2, you must set the video output format and encoding parameters:
>
> setOutputFormat() – Set the output format, specify the default setting or 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.
Set the video encoding type, specify the default setting or MediaRecorder.VideoEncoder.MPEG_4_SP. というのは、指定しなければMPEG_4_SPが指定されるのかと思っていました。
/** A safe way to get an instance of the Camera object. */
public static Camera getCameraInstance(){
Camera c = null;
try {
c = Camera.open(); // attempt to get a Camera instance
}
catch (Exception e){
// Camera is not available (in use or does not exist)
}
return c; // returns null if camera is unavailable
}
ビデオの注意点
上記でカメラを作ってみたら、次はビデオです。
ビデオを動かすためには順番がかなり大事。
カメラをopen()する – Use the Camera.open() to get an instance of the camera object.
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
@Override
protected void onPause() {
super.onPause();
releaseMediaRecorder(); // if you are using MediaRecorder, release it first
releaseCamera(); // release the camera immediately on pause event
}
private void releaseMediaRecorder(){
if (mMediaRecorder != null) {
mMediaRecorder.reset(); // clear recorder configuration
mMediaRecorder.release(); // release the recorder object
mMediaRecorder = null;
mCamera.lock(); // lock camera for later use
}
}
private void releaseCamera(){
if (mCamera != null){
mCamera.release(); // release the camera for other applications
mCamera = null;
}
}