有没有人设法在Glass上使用MediaRecorder成功录制视频?
这是我用来准备记录器的代码。我一直收到错误-19。
recorder = new MediaRecorder();
recorder.setOutputFile(videoFile);
recorder.setVideoSource(MediaRecorder.VideoSource.DEFAULT);
recorder.setAudioSource(MediaRecorder.AudioSource.DEFAULT);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setVideoFrameRate(15);
recorder.setVideoEncoder(MediaRecorder.VideoEncoder.DEFAULT);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
谢谢。
更新: 它似乎是一个GDK错误。我报告了它并且它被接受了。如果您遇到同样的问题,请将错误报告加以通知:
https://code.google.com/p/google-glass-api/issues/detail?id=360
答案 0 :(得分:2)
要在Glass上开始视频捕获,您似乎必须完全停止视频预览。如果您使用预览相机,在使用MediaRecorder执行任何操作之前,只需运行:
try {
mCamera.setPreviewDisplay(null);
} catch (java.io.IOException ioe) {
Log.d(TAG, "IOException nullifying preview display: " + ioe.getMessage());
}
mCamera.stopPreview();
mCamera.unlock();
此处有更多信息:https://code.google.com/p/google-glass-api/issues/detail?id=360#c6
答案 1 :(得分:1)
经过多次挫折和迭代后,我很高兴地报告可以在Glass XE12上使用MediaRecorder。以下代码适用于运行XE12的Glass版本1:
mMediaRecorder = new MediaRecorder();
mMediaRecorder.setCamera(mCamera);
mMediaRecorder.setPreviewDisplay(preview.getHolder().getSurface());
mCamera.unlock();
// Step 2: Set sources
mMediaRecorder.setOnErrorListener(new android.media.MediaRecorder.OnErrorListener() {
public void onError(MediaRecorder mediarecorder1, int k, int i1)
{
Log.e(TAG,String.format("Media Recorder error: k=%d, i1=%d", k, i1));
}
});
mMediaRecorder.setVideoSource(0);
mMediaRecorder.setAudioSource(0);
mMediaRecorder.setOutputFormat(2);
mMediaRecorder.setVideoEncoder(2);
mMediaRecorder.setVideoEncodingBitRate(0x4c4b40);
mMediaRecorder.setVideoFrameRate(30);
mMediaRecorder.setVideoSize(1280, 720);
mMediaRecorder.setAudioChannels(2);
mMediaRecorder.setAudioEncoder(3);
mMediaRecorder.setAudioEncodingBitRate(0x17700);
mMediaRecorder.setAudioSamplingRate(44100);
mMediaRecorder.setMaxDuration(0);
mMediaRecorder.setOutputFile(getOutputMediaFile(MEDIA_TYPE_VIDEO).toString());
mMediaRecorder.setMaxDuration(-1);
// Step 5: Set the preview output
// Step 6: Prepare configured MediaRecorder
try {
mMediaRecorder.prepare();
mMediaRecorder.start();
} 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;
} catch (Exception e) {
Log.d(TAG, "Unknown exception preparing MediaRecorder: " + e.getMessage());
releaseMediaRecorder();
return false;
}
答案 2 :(得分:0)
您何时准备录音机,启动应用程序时会发生什么?如果是这样,你是否用语音触发器启动它?
如果这两件事都是真的,那么这可能是the bug described here的一个实例。您可以尝试该线程中的变通方法(指数退避)并查看它是否有效吗?