很多Android機上會出現(xiàn)surfaceView結(jié)束播放后详幽,出現(xiàn)概率的黑塊,典型的解決方案
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.
*
* <p>Note that this must be set before the surface view's containing
* window is attached to the window manager.
*
* <p>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.
*
* <p>Note that this must be set before the surface view's containing
* window is attached to the window manager.
*
* <p>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;
}
}
實際上根本沒有用!
那么下面代碼可以嗎浸锨?
\\設(shè)置透明
setAlpha(0);
\\設(shè)置不可見
setVisibility(GONE);
實際也沒有用!
最終得這樣才行
release();
找到對應(yīng)的“drawer”唇聘,然后釋放掉渲染器才行!V选迟郎!
參考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.");
}