Android Camera 2 Api [英] Android Camera 2 Api

查看:159
本文介绍了Android Camera 2 Api的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试使用camera2 API.我已经从

I have been trying camera2 API. I have downloaded code from

https://developer.android.com/samples/Camera2Video/index.html 进行学习关于它是如何工作的.直到我停止录制为止,它都可以正常工作.当我停止记录时,它将运行以下代码.

https://developer.android.com/samples/Camera2Video/index.html to learn about how it works. It works fine till I stop recording. When I stop recording it runs following code.

 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();它会引发以下错误

at mMediaRecorder.stop(); it throw following error

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)

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

Any Idea what I am doing wrong. I spent few hours but couldn't find any solution.

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

Edit - I am using geneymotion emulator. The path I am using

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

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

谢谢

推荐答案

我的解决方案是按以下方式更改void stopRecordingVideo():

My solution is to change void stopRecordingVideo() as following:

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 Camera 2 Api的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆