Android相机2 Api

前端之家收集整理的这篇文章主要介绍了Android相机2 Api前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我一直在尝试camera2 API.我已经下载了代码

https://developer.android.com/samples/Camera2Video/index.html了解它是如何工作的.它工作正常,直到我停止录音.当我停止录制时,运行以下代码.

private void stopRecordingVideo() {
        // UI
        mIsRecordingVideo = false;
        mBtn_Video.setText(R.string.record);
        // Stop recording
        try {
            mMediaRecorder.stop();
            mMediaRecorder.reset();
        }
        catch (Exception e) {
            e.printStackTrace();
        }
        Activity activity = getActivity();
        if (null != activity) {
            System.out.println("file " +  getVideoFile(activity));
            Toast.makeText(activity,"Video saved: " + getVideoFile(activity),Toast.LENGTH_SHORT).show();
        }
        startPreview();

在mMediaRecorder.stop();它会抛出以下错误

01-12 16:24:23.115    2161-2200/com.cameratwoapi E/Surface﹕ queueBuffer: error queuing buffer to SurfaceTexture,-19
01-12 16:24:23.135    2161-2200/com.cameratwoapi E/EGL_emulation﹕ tid 2200: swapBuffers(285): error 0x3003 (EGL_BAD_ALLOC)
01-12 16:24:23.197    2161-2200/com.cameratwoapi E/CameraDeviceGLThread-0﹕ Received exception on GL render thread:
    java.lang.IllegalStateException: swapBuffers: EGL error: 0x3003
            at android.hardware.camera2.legacy.SurfaceTextureRenderer.checkEglError(SurfaceTextureRenderer.java:487)
            at android.hardware.camera2.legacy.SurfaceTextureRenderer.swapBuffers(SurfaceTextureRenderer.java:480)
            at android.hardware.camera2.legacy.SurfaceTextureRenderer.drawIntoSurfaces(SurfaceTextureRenderer.java:681)
            at android.hardware.camera2.legacy.GLThreadManager$1.handleMessage(GLThreadManager.java:103)
            at android.os.Handler.dispatchMessage(Handler.java:98)
            at android.os.Looper.loop(Looper.java:135)
            at android.os.HandlerThread.run(HandlerThread.java:61)

任何想法我做错了什么我花了几个小时,但找不到任何解决方案.

编辑 – 我正在使用geneymotion模拟器.我正在使用的路径

file /storage/emulated/0/Android/data/com.gold.cameratwoapi/files/video.mp4

谢谢

解决方法

我的解决办法是改变void stopRecordingVideo()如下:
private void stopRecordingVideo() {
// UI
mIsRecordingVideo = false;
mButtonVideo.setText(R.string.record);
// Added by Ben Ning,to resolve exception issue when stop recording.
try {
    mPreviewSession.stopRepeating();
    mPreviewSession.abortCaptures();
} catch (CameraAccessException e) {
    e.printStackTrace();
} 

// Stop recording
mMediaRecorder.stop();
mMediaRecorder.reset();

}

关键是:

try {
    mPreviewSession.stopRepeating();
    mPreviewSession.abortCaptures();
} catch (CameraAccessException e) {
    e.printStackTrace();
}

猜你在找的Android相关文章