很多Android机上会出现surfaceView结束播放后,出现概率的黑块,典型的解决方案

setZOrderMediaOverlay(false);

setZorderTop(false);

/**

* Control whether the surface view's surface is placed on top of another

* regular surface view in the window (but still behind the window itself).

* This is typically used to place overlays on top of an underlying media

* surface view.

*

*

Note that this must be set before the surface view's containing

* window is attached to the window manager.

*

*

Calling this overrides any previous call to {@link #setZOrderOnTop}.

*/

public void setZOrderMediaOverlay(boolean isMediaOverlay) {

mWindowType = isMediaOverlay

? WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY

: WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA;

}

/**

* Control whether the surface view's surface is placed on top of its

* window. Normally it is placed behind the window, to allow it to

* (for the most part) appear to composite with the views in the

* hierarchy. By setting this, you cause it to be placed above the

* window. This means that none of the contents of the window this

* SurfaceView is in will be visible on top of its surface.

*

*

Note that this must be set before the surface view's containing

* window is attached to the window manager.

*

*

Calling this overrides any previous call to {@link #setZOrderMediaOverlay}.

*/

public void setZOrderOnTop(boolean onTop) {

if (onTop) {

mWindowType = WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;

// ensures the surface is placed below the IME

mLayout.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;

} else {

mWindowType = WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA;

mLayout.flags &= ~WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;

}

}

实际上根本没有用!

那么下面代码可以吗?

\\设置透明

setAlpha(0);

\\设置不可见

setVisibility(GONE);

实际也没有用!

最终得这样才行

release();

找到对应的“drawer”,然后释放掉渲染器才行!!!

参考webrtc代码

public void release() {

this.logD("Releasing.");

final CountDownLatch eglCleanupBarrier = new CountDownLatch(1);

Object var2 = this.handlerLock;

synchronized(this.handlerLock) {

if(this.renderThreadHandler == null) {

this.logD("Already released");

return;

}

this.renderThreadHandler.removeCallbacks(this.logStatisticsRunnable);

this.renderThreadHandler.postAtFrontOfQueue(new Runnable() {

public void run() {

if(EglRenderer.this.drawer != null) {

EglRenderer.this.drawer.release();

EglRenderer.this.drawer = null;

}

if(EglRenderer.this.yuvTextures != null) {

GLES20.glDeleteTextures(3, EglRenderer.this.yuvTextures, 0);

EglRenderer.this.yuvTextures = null;

}

if(EglRenderer.this.bitmapTextureFramebuffer != null) {

EglRenderer.this.bitmapTextureFramebuffer.release();

EglRenderer.this.bitmapTextureFramebuffer = null;

}

if(EglRenderer.this.eglBase != null) {

EglRenderer.this.logD("eglBase detach and release.");

EglRenderer.this.eglBase.detachCurrent();

EglRenderer.this.eglBase.release();

EglRenderer.this.eglBase = null;

}

eglCleanupBarrier.countDown();

}

});

final Looper renderLooper = this.renderThreadHandler.getLooper();

this.renderThreadHandler.post(new Runnable() {

public void run() {

EglRenderer.this.logD("Quitting render thread.");

renderLooper.quit();

}

});

this.renderThreadHandler = null;

}

ThreadUtils.awaitUninterruptibly(eglCleanupBarrier);

var2 = this.frameLock;

synchronized(this.frameLock) {

if(this.pendingFrame != null) {

VideoRenderer.renderFrameDone(this.pendingFrame);

this.pendingFrame = null;

}

}

this.logD("Releasing done.");

}

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐