【发布时间】:2014-05-31 16:01:27
【问题描述】:
我正在开发一个录制视频的应用程序。
我在我的应用程序中得到了这段代码,它在 Nexus 4 和索尼爱立信 mini pro 中运行良好,但是当我在其他设备上测试时,如爱可视 80G9 和佳宇 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;
}
我试过了:
- 在
mediarecorder.start()之前放一个thread.sleep(1000);但这会给我一个错误。 - 在 development.android.com 中放置一个 Default CameraPreview。
- 我的应用使用自定义 CameraPreview 调整预览大小。
- 我使用
CamcorderProfile.hasProfile(CamcorderProfile.QUALITY_720P)获得相机质量,因为这总是使用在手机上工作的配置文件。
【问题讨论】:
标签: android camera mediarecorder