开始第二次活动后相机无法工作 [英] Camera doesn't work after starting second activity

查看:222
本文介绍了开始第二次活动后相机无法工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始使用新的camera2 API。

I started working with the new camera2 API.

我在我的 TextureView 上运行摄像机预览第一个活动。我可以通过导航抽屉启动第二个活动。我也想让我在 TextureView 中向我展示一个相机预览。不幸的是,屏幕保持白色,我看不到图片。我不知道该错误,也找不到它:

I run a camera preview on a TextureView in my first Activity. Via my navigation drawer can I start a second Activity. I want this one to show me a camera preview in a TextureView, too. Unfortunately, the screen stays white and I don't see a picture. I don't know the error and couldn't find something about it:

5278-5414/de.application E/CameraDeviceGLThread-0﹕ Received exception on GL render thread:
    java.lang.IllegalStateException: swapBuffers: EGL error: 0x300d
            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:211)
            at android.os.HandlerThread.run(HandlerThread.java:61) 06-01 23:00:44.258    5278-5414/de.application I/CameraDeviceState﹕ Legacy camera service transitioning to state ERROR

我非常简单地启动了新的Activity,并且摄像头的功能

I start the new Activity pretty simple, and the functions for the camera are in both Activitys more or less the same.

Intent i = new Intent(MainActivityOld.this, FullScreenActivity.class);
startActivity(i);

你能想象我犯了一个错误吗?我是否必须以某种方式停止第一个Camera Preview?

Can you imagine a mistake I make? Do I have to stop the first Camera Preview somehow?

推荐答案

通常,当TextureView不再消失时,它会关闭其SurfaceTexture输出显示。因此,当您的第一个Activity进入后台时,TextureView不再是相机数据的有效目标。

Generally, a TextureView tears down its SurfaceTexture output when it is no longer displayed. So when your first Activity goes into the background, the TextureView is no longer a valid target for camera data.

您打算如何将预览数据发送到第二个Activity的TextureView ?您需要在发生切换时将预览缓冲区的流切换为第二个TextureView的目标。您可以通过在切换到第二个活动时创建一个针对第二个TextureView的新相机捕获会话来实现此目的。

How were you intending to send preview data to your second Activity's TextureView? You'll need to switch the flow of preview buffers to target the second TextureView when the switchover occurs. You can do this by creating a new camera capture session that targets the second TextureView, when you switch to the second activity.

这篇关于开始第二次活动后相机无法工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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