Search code examples
androidopengl-es-2.0android-mediaplayerqcar-sdk

OpenGL Context destroyed after quitting from 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?


Solution

  • 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.