我利用service进行后台录像,有视频文件生成,但是是无法播放的视频文件,不知道是程序里哪里有错,望各位高手指点一二,再次谢过啦~~~
public class recorder extends Service{
public static final int MEDIA_TYPE_IMAGE = 1;
public static final int MEDIA_TYPE_VIDEO = 2;
private Camera mCamera01;
private MediaRecorder mRecorder01;
@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
stop_camera();
mCamera01.stopPreview();
mCamera01.release();
mCamera01 = null;
Toast.makeText(this,"STOP",Toast.LENGTH_SHORT).show();
}
@Override
public void onStart(Intent intent, int startId) {
// TODO Auto-generated method stub
super.onStart(intent, startId);
init_camera();
}
private void init_camera()
{
Toast.makeText(this,"start",Toast.LENGTH_SHORT).show();
// mCamera01 = Camera.open();
if(null == mCamera01)
mCamera01 = Camera.open();
mCamera01.stopPreview();
mCamera01.unlock();
mRecorder01 = new MediaRecorder();// 创建mRecorder对象
mRecorder01.setCamera(mCamera01);// 设置录制视频源为Camera(相机)
mRecorder01.setVideoSource(MediaRecorder.VideoSource.CAMERA);
mRecorder01.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
mRecorder01.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_HIGH));
// mRecorder01.setPreviewDisplay(mSurfaceHolder01.getSurface());
mRecorder01.setOutputFile(getOutputMediaFile(MEDIA_TYPE_VIDEO).toString());
try {
// 准备录制
mRecorder01.prepare();