Question

Has anyone managed to successfully record a video using MediaRecorder on Glass?

This is the code i am using in order to prepare the Recorder. I keep getting error -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); 

Thank you.

Update: It seems to be a GDK bug. I have reported it and it got accepted. If you are having the same issue just star the bug report to stay informed:

https://code.google.com/p/google-glass-api/issues/detail?id=360

Was it helpful?

Solution

To start video capture on Glass it seems that you have to completely stop the video preview. If you are using a previewing camera, prior of doing anything with a MediaRecorder, just run:

try {
    mCamera.setPreviewDisplay(null);
} catch (java.io.IOException ioe) {
    Log.d(TAG, "IOException nullifying preview display: " + ioe.getMessage());
}
mCamera.stopPreview();
mCamera.unlock();

More info here: https://code.google.com/p/google-glass-api/issues/detail?id=360#c6

OTHER TIPS

After much frustration and iteration, I'm pleased to report that it IS possible to use MediaRecorder on Glass XE12. The below code works for me on my Glass Version 1 running XE12:

    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;
    }

When do you prepare the recorder, is it something that happens when you launch your application? If so, are you launching it with a voice trigger?

If both of those things are true, this might be an instance of the bug described here. Can you try the workaround in that thread (exponential backoff) and see if it works?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top