首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何清除GLSurfaceView

如何清除GLSurfaceView
EN

Stack Overflow用户
提问于 2014-07-21 15:51:03
回答 3查看 2K关注 0票数 2

我正在使用视频流的GLSurfaceView。万事如意。但是当流结束时,GLSurfaceView中还有剩余的图片。如何从GLSurfaceView中删除图片?

顺便说一句,当我跳到她的活动并返回时,剩下的图片就不见了。

我用这个解决了我的问题: GLSurfaceView.setVisiblility(View.Invisible);GLSurfaceView.setVisiblility(View.Visible);这样GLSurfaceView就可以重新绘制自己;

期待一个更好的答案。

EN

回答 3

Stack Overflow用户

发布于 2014-07-21 16:03:37

尝试在视频流结束后调用requestRender()。

票数 0
EN

Stack Overflow用户

发布于 2014-07-21 18:22:32

试试这个神奇的代码:

代码语言:javascript
复制
    view.setRenderer(new Renderer() {

        @Override
        public void onSurfaceCreated(GL10 gl, EGLConfig config) {
        }

        @Override
        public void onSurfaceChanged(GL10 gl, int width, int height) {
        }

        @Override
        public void onDrawFrame(GL10 gl) {
            // here are Red, Green, Blue and Alpha values between 0 and 1
            GLES20.glClearColor(0, 0, 0, 1); 
            GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);                
        }
    });
票数 0
EN

Stack Overflow用户

发布于 2022-01-13 12:41:12

我有一个问题,当切换源(和视频组件),但表面仍然显示旧的帧,但我需要黑屏。

对我有效的是,所有的动作都是在渲染器中完成的(impl。GLSurfaceView.Renderer)类:

  1. create AtomicBoolean,初始值为false (也称为用于清除表面的example);
  2. function中的stopRendering (通过OpenGL):

代码语言:javascript
复制
 private void clearSurface() {
     GLES20.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
     GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
 }

然后,

  1. 函数清除并停止渲染(我在切换播放器的VideoComponent时调用它):

代码语言:javascript
复制
 public void clearAndStopRendering() {
     stopRendering.set(true);
     glSurface.requestRender();
 }

  1. 在帧准备就绪时恢复帧渲染:

代码语言:javascript
复制
    @Override
   public void onVideoFrameAboutToBeRendered(long presentationTimeUs, long releaseTimeNs, @NonNull Format format, @Nullable MediaFormat mediaFormat) {
       if (stopRendering.compareAndSet(true, false)) {
           glSurface.requestRender();
       }
   }

我的onDrawFrame是什么样子:

代码语言:javascript
复制
    @Override
    public void onDrawFrame(GL10 gl) {
        // some initialization code, related to my work      

        if (stopRendering.get()) {
            clearSurface();
            return;
        }

        // Drawing ...
    }

我在GLSurfaceView中的代码,在那里我触发了清除:

代码语言:javascript
复制
    public void setVideoComponent(@Nullable Player.VideoComponent newVideoComponent) {
        if (newVideoComponent == videoComponent) {
            return;
        }
        if (videoComponent != null) {
            // clearing old VideoComponent
            renderer.clearAndStopRendering();
        }
        videoComponent = newVideoComponent;
        // setup new VideoComponent 
    }

所以,我实现了:每次当VideoComponent改变(通过自定义的PlayerView,其中包括我的GLSurfaceView),黑屏渲染,然后,在视频帧准备好后,渲染它,而不是旧的帧。

P.S. BTW第二个变体,如果你像我一样使用自定义PlayerView,你可以这样做:

代码语言:javascript
复制
class MyGlPlayerView @JvmOverloads constructor(
    context: Context, attrs: AttributeSet? = null
) : PlayerView(context, attrs), MyPlayerView {

    private lateinit var glSurfaceView: MyGLSurfaceView

    override fun onFinishInflate() {
        super.onFinishInflate()

        val contentFrame = findViewById<FrameLayout>(R.id.exo_content_frame)

        glSurfaceView = MyGLSurfaceView(context, false);

        contentFrame.addView(glSurfaceView, 0)
        setShutterBackgroundColor(Color.BLACK)
    }

    override fun setPlayer(player: Player?) {
        glSurfaceView.setVideoComponent(player?.videoComponent)

        super.setPlayer(player)
    }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24860086

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档