我正在使用视频流的GLSurfaceView。万事如意。但是当流结束时,GLSurfaceView中还有剩余的图片。如何从GLSurfaceView中删除图片?
顺便说一句,当我跳到她的活动并返回时,剩下的图片就不见了。
我用这个解决了我的问题: GLSurfaceView.setVisiblility(View.Invisible);GLSurfaceView.setVisiblility(View.Visible);这样GLSurfaceView就可以重新绘制自己;
期待一个更好的答案。
发布于 2014-07-21 16:03:37
尝试在视频流结束后调用requestRender()。
发布于 2014-07-21 18:22:32
试试这个神奇的代码:
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);
}
});发布于 2022-01-13 12:41:12
我有一个问题,当切换源(和视频组件),但表面仍然显示旧的帧,但我需要黑屏。
对我有效的是,所有的动作都是在渲染器中完成的(impl。GLSurfaceView.Renderer)类:
AtomicBoolean,初始值为false (也称为用于清除表面的example);stopRendering (通过OpenGL): 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);
}然后,
VideoComponent时调用它): public void clearAndStopRendering() {
stopRendering.set(true);
glSurface.requestRender();
} @Override
public void onVideoFrameAboutToBeRendered(long presentationTimeUs, long releaseTimeNs, @NonNull Format format, @Nullable MediaFormat mediaFormat) {
if (stopRendering.compareAndSet(true, false)) {
glSurface.requestRender();
}
}我的onDrawFrame是什么样子:
@Override
public void onDrawFrame(GL10 gl) {
// some initialization code, related to my work
if (stopRendering.get()) {
clearSurface();
return;
}
// Drawing ...
}我在GLSurfaceView中的代码,在那里我触发了清除:
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,你可以这样做:
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)
}https://stackoverflow.com/questions/24860086
复制相似问题