大多数情况下,我想知道是否存在我无法与图书馆共享相同资源的根本冲突,如果是这样,我将需要采取不同的方法。
我的目标是同时保存检测器元数据的低质量视频,这样我就可以在没有太多延迟的情况下进行一些后期处理和切片。
我一直在初始化 MediaRecorder,但如果我在检测器之前启动它会保存一个黑屏,如果我在检测器之后启动它,它会在启动时崩溃(代码 -19)。检测器正在附加预览,可能与此有关。
我添加了一些按钮来控制这些功能:
protected void cameraInit() {
String state = Environment.getExternalStorageState();
if (!Environment.MEDIA_MOUNTED.equals(state)) {
Log.d(LOG_TAG, "Drive not mounted - cannot write video");
return;
}
File file = new File(getExternalFilesDir(Environment.DIRECTORY_MOVIES), "demo.gp3");
Log.d(LOG_TAG, String.format("Camera Initializing. Setting output to: %s", file.getAbsolutePath()));
// Set sources
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setVideoSource(MediaRecorder.VideoSource.CAMERA);
// Set profile
recorder.setProfile(CamcorderProfile.get(CamcorderProfile.QUALITY_LOW));
// Set output profile
recorder.setOutputFile(file.getAbsolutePath());
// Set preview output
recorder.setPreviewDisplay(cameraPreview.getHolder().getSurface());
try {
this.recorder.prepare();
} catch (IOException e) {
Log.e(LOG_TAG, "IO exception on camera Initialization");
e.printStackTrace();
} catch (IllegalStateException e) {
// This is thrown if the previous calls are not called with the
// proper order
Log.e(LOG_TAG, "Failed to initialize things properly :( ");
e.printStackTrace();
}
}
protected void cameraStart() {
Log.d(LOG_TAG, "Camera Start");
this.recorder.start();
}
protected void cameraStop() {
Log.d(LOG_TAG, "Camera Stop");
this.recorder.stop();
}