Clean surface with black rectangle

I am using Exoplayer and GL SurfaceTexture (from TextureView) to display video. I am using reuse of the same surface for video playback.

I release the player and create a new instance. When SurfaceTexture is rendered a second time, displays the old texture from the last video until the player starts playing and fills the surface with black.

I am looking for a way to draw a black rectangle to fill the surface with black, but could not achieve that.

+3


source to share


3 answers


Using @fadden's link on Grafika, I created my own script to clean up the surface. It is API 16 compliant.

GIST



/**
 * Clear the given surface Texture by attaching a GL context and clearing the surface.
 * @param texture a valid SurfaceTexture
 */
private void clearSurface(SurfaceTexture texture) {
    if(texture == null){
        return;
    }

    EGL10 egl = (EGL10) EGLContext.getEGL();
    EGLDisplay display = egl.eglGetDisplay(EGL10.EGL_DEFAULT_DISPLAY);
    egl.eglInitialize(display, null);

    int[] attribList = {
            EGL10.EGL_RED_SIZE, 8,
            EGL10.EGL_GREEN_SIZE, 8,
            EGL10.EGL_BLUE_SIZE, 8,
            EGL10.EGL_ALPHA_SIZE, 8,
            EGL10.EGL_RENDERABLE_TYPE, EGL10.EGL_WINDOW_BIT,
            EGL10.EGL_NONE, 0,      // placeholder for recordable [@-3]
            EGL10.EGL_NONE
    };
    EGLConfig[] configs = new EGLConfig[1];
    int[] numConfigs = new int[1];
    egl.eglChooseConfig(display, attribList, configs, configs.length, numConfigs);
    EGLConfig config = configs[0];
    EGLContext context = egl.eglCreateContext(display, config, EGL10.EGL_NO_CONTEXT, new int[]{
            12440, 2,
            EGL10.EGL_NONE
    });
    EGLSurface eglSurface = egl.eglCreateWindowSurface(display, config, texture,
            new int[]{
                    EGL10.EGL_NONE
            });

    egl.eglMakeCurrent(display, eglSurface, eglSurface, context);
    GLES20.glClearColor(0, 0, 0, 1);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    egl.eglSwapBuffers(display, eglSurface);
    egl.eglDestroySurface(display, eglSurface);
    egl.eglMakeCurrent(display, EGL10.EGL_NO_SURFACE, EGL10.EGL_NO_SURFACE,
            EGL10.EGL_NO_CONTEXT);
    egl.eglDestroyContext(display, context);
    egl.eglTerminate(display);
}

      

+9


source


I'm not familiar with Exoplayer, but I suspect your options are the same as for playing with MediaPlayer mentioned in this answer .

Summary:



  • You can attach GLES, clean surface, detach GLES ( Grafika does this ).
  • You can create a one-shot black video and play it back.
  • You can create a second, empty view that overlaps the first. Hide it during video playback and show it when video is done.

What you cannot do is attach the canvas and clear it, because once the Canvas is attached it never lets go.

+2


source


Please call GLES20.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

before drawing a new frame

-1


source







All Articles