您好我正在尝试在Android中的硬件相机控件, 我能够在表面视图上预览相机, 但是我无法录制任何视频,因为在开始视频录制时我收到以下错误:
媒体服务器死了
相机服务器已经死亡
ICamera去世了
错误100
捕获代码如下
public void onCaptureClick(View view){
if(!isRecording)
new MediaPrepareTask().execute(null,null,null);
else{
mMediaRecorder.stop();
releaseMediaRecorder();
mCamera.lock();
setCaptureButtonText("Start");
isRecording = false ;
releaseCamera();
}
}
这是媒体准备任务
class MediaPrepareTask extends AsyncTask<Void, Void, Boolean>{
@Override
protected Boolean doInBackground(Void... arg0) {
if (prepareVideoRecorder()) {
// Camera is available and unlocked, MediaRecorder is prepared,
// now you can start recording
mMediaRecorder.start();
Log.i(TAG,"Media recording started");
isRecording = true;
} else {
// prepare didn't work, release the camera
releaseMediaRecorder();
return false;
}
return true;
}
@Override
protected void onPostExecute(Boolean result){
if(!result){
MainActivity.this.finish();
}
setCaptureButtonText("Stop");
}
}
这是我设置录制属性的地方
private boolean prepareVideoRecorder(){
Log.i(TAG,"Starting to prepare");
Camera.Parameters parameters = mCamera.getParameters() ;
Log.i(TAG,"Got Property");
List<Camera.Size> mSupportedPreviewSize = parameters.getSupportedPreviewSizes();
Camera.Size optimalSize = CameraHelper.getOptimalPreviewSize(mSupportedPreviewSize,
mPreview.getWidth(), mPreview.getHeight());
CamcorderProfile profile = CamcorderProfile.get(CamcorderProfile.QUALITY_LOW);
profile.videoFrameWidth = optimalSize.width ;
profile.videoFrameHeight = optimalSize.height ;
parameters.setPreviewSize(profile.videoFrameWidth, profile.videoFrameHeight);
mCamera.setParameters(parameters);
Log.i(TAG,"Set Parameters");
try{
// // mCamera.setPreviewTexture(mPreview.getSurfaceTexture());
mCamera.setPreviewDisplay(mPreview.getHolder());
}catch(IOException iOEx){
iOEx.printStackTrace();
Log.e(TAG, "Failed to set preview display ");
return false ;
}
////////////////////////////////now for the media recorder ///////////////////////
mMediaRecorder = new MediaRecorder();
mCamera.unlock();
mMediaRecorder.setCamera(mCamera);
Log.i(TAG,"Set camera for recorder");
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
mMediaRecorder.setProfile(profile);
Log.i(TAG,CameraHelper.getOutputMediaFile(CameraHelper.MEDIA_TYPE_VIDEO).toString());
mMediaRecorder.setOutputFile(CameraHelper.getOutputMediaFile(
CameraHelper.MEDIA_TYPE_VIDEO).toString());
// END_INCLUDE (configure_media_recorder)
// Step 5: Prepare configured MediaRecorder
Log.i(TAG,"Set the ouptut format");
try {
mMediaRecorder.prepare();
} catch (IllegalStateException e) {
Log.d(TAG, "IllegalStateException preparing MediaRecorder: " + e.getMessage());
releaseMediaRecorder();
return false;
} catch (IOException e) {
Log.d(TAG, "IOException preparing MediaRecorder: " + e.getMessage());
releaseMediaRecorder();
return false;
}
Log.i(TAG,"All is well");
return true;
}
答案 0 :(得分:0)
这适用于任何阅读该问题的人
问题在于表面也要添加到媒体记录器中,
只需将表面添加到介质记录器即可正常工作