我正在开发一款录制视频的应用。
我在我的应用程序中获得了此代码,该代码在Nexus 4和Sony Ericsson mini pro中运行良好,但当我在其他设备上测试时,如Archos 80G9和Jiayu G3ST,该应用程序给我以下错误
“MediaRecorder启动失败-19”
或有时
“相机错误100”。
我尝试实现其他stackoverflow帖子中建议的一些更改,但仍然出现错误。
private boolean prepareVideoRecorder() {
/** ADDED Sony Ericsson Stoped */
try {
mCamera.setPreviewDisplay(null);
} catch (java.io.IOException ioe) {
Log.d(TAG,
"IOException nullifying preview display: "
+ ioe.getMessage());
}
mCamera.stopPreview();
mMediaRecorder = new MediaRecorder();
// Step 1: Unlock and set camera to MediaRecorder
mCamera.unlock();
mMediaRecorder.setCamera(mCamera);
// Step 2: Set sources
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
mMediaRecorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
// Step 3: Set a CamcorderProfile (requires API Level 8 or higher)
CameraBackFront cm = new CameraBackFront();
int id = cm.getBackCameraId();
if (qualityString().equalsIgnoreCase("Low")) {
mMediaRecorder.setProfile(CamcorderProfile.get(id,
CamcorderProfile.QUALITY_LOW));
} else if (qualityString().equalsIgnoreCase("High")) {
mMediaRecorder.setProfile(CamcorderProfile.get(id,
CamcorderProfile.QUALITY_HIGH));
} else if (qualityString().equalsIgnoreCase("480p")) {
mMediaRecorder.setProfile(CamcorderProfile.get(id,
CamcorderProfile.QUALITY_480P));
} else if (qualityString().equalsIgnoreCase("720p")) {
mMediaRecorder.setProfile(CamcorderProfile.get(id,
CamcorderProfile.QUALITY_720P));
} else if (qualityString().equalsIgnoreCase("1080p")) {
try {
mMediaRecorder.setProfile(CamcorderProfile.get(id,
CamcorderProfile.QUALITY_1080P));
} catch (Exception e) {
mMediaRecorder.setProfile(CamcorderProfile.get(id,
CamcorderProfile.QUALITY_HIGH));
}
} else {
mMediaRecorder.setProfile(CamcorderProfile.get(0,
CamcorderProfile.QUALITY_HIGH));
}
// Step 4: Set output file
mMediaRecorder.setOutputFile(getOutputMediaFile(MEDIA_TYPE_VIDEO)
.toString());
/** ADD FILE NAME */
addFileNameDB();
// Step 5: Set the preview output
mMediaRecorder.setPreviewDisplay(mPreview.getHolder().getSurface());
// Step 6: Prepare configured MediaRecorder
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;
}
return true;
}
我试过了:
thread.sleep(1000);
之前加mediarecorder.start()
,但这给了我一个错误。CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_720P)
获取相机质量,因为这总是使用可在手机上运行的配置文件。 答案 0 :(得分:1)
最后我用
解决了我的问题...
releaseCamera();
if(prepareVideoRecorder){
...
}
在prepareVideoRecorder()之前。
并进入prepareVideoRecorder添加一个新的相机实例。
public void prepareVideoRecorder(){
mCamera = getCameraInstance();
...
}
我已经修好了这件事: