从 MediaPlayer 退出后 OpenGL 上下文被破坏
我们有一个增强现实应用程序,当指向特定标记时,它会显示视频或 3D 模型。这工作得很好,但是一旦我们通过后退按钮退出 MediaPlayer 活动,OpenGL 上下文似乎就会被破坏。然后应用程序将重新启动,并需要重新加载包括 3D 模型在内的所有资源,这会导致大约 10-15 秒的延迟,而我们希望避免这种情况。 我已经读过一些关于 setPreserveEGLContextOnPause(true) 的内容,并将其放入我们的 GLSurfaceView 中(我们有一个 3.x 平板电脑),但它似乎没有做任何事情(我是否需要实现其他东西来让它工作吗?我几乎找不到有关它的可用文档)。
我不确定我们的应用程序中的问题可能出在哪里,我想我们的 GLSurface 的某个地方被破坏了,而我们没有注意到它。
我们从 MediaPlayer 退出的代码是这样的:
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK)) {
this.finish();
Intent intent = new Intent(MediaPlayerActivity.this, OpenGLActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.startActivity(intent);
}
return super.onKeyDown(keyCode, event);
}
有什么提示我们可以保留 OpenGL 上下文,或者退出 MediaPlayer 而不破坏我们的主要活动吗?
We have an Augmented Reality app that displays either a video or a 3D model when pointing on a specific marker. This works fine, but as soon as we quit the MediaPlayer activity via the Back-Button, the OpenGL Context seems to get destroyed. The app then just restarts and needs to reload all assets including the 3D model which causes a delay of about 10-15 seconds which we want to prevent.
I read already something about setPreserveEGLContextOnPause(true) and put it in our GLSurfaceView (we have a 3.x tablet), but it doesn't seem to do anything (do I need to implement something else to make it work? I barely found usable documentation about it).
I'm not sure where in our app the problem could be, I suppose that somewhere our GLSurface gets destroyed and we dont notice it.
Our code from exiting from the MediaPlayer is this:
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK)) {
this.finish();
Intent intent = new Intent(MediaPlayerActivity.this, OpenGLActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.startActivity(intent);
}
return super.onKeyDown(keyCode, event);
}
Any hints how we can preserve the OpenGL context, or quit the MediaPlayer without trashing our main activity?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为了解决这个问题,我们将 MediaPlayer 放在 SurfaceView 层上,它将显示在我们的 OpenGL 内容之上。根据标记,我们只是显示或隐藏图层并防止脱离上下文。
To get around that, we have put the MediaPlayer on a SurfaceView layer, that will display over our OpenGL stuff. Depending on the marker, we just show or hide the layer and prevent switching out of context.