libgdx / gdx-video

A libGDX cross platform video rendering extension
Apache License 2.0
145 stars 48 forks source link

Screen flickers to black if you loop a video #40

Closed lakrsv closed 3 years ago

lakrsv commented 7 years ago

I have a loopable video that I am looping by doing this in the render loop (Android):

Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
 if (videoPlayer != null) {
            if (!videoPlayer.render()) {
                try {
                    videoPlayer.play(movieFile);
                } catch (FileNotFoundException e) {
                    videoPlayer = null;
                    Gdx.app.log("EXCEPTION", "Could not loop video", e);
                }
            }
        }

Whenever the video is done playing, it will flicker once to black before it resumes playing. Currently I remove the glClear to make it less visible, but this is not really an approach I'd like to keep in the future.

Anyone have any suggestions or is this a limitation in the android mediaplayer?

RBogie commented 7 years ago

I can't remember having this issue back when I tested a looping video on android. It is probably something device specific. It means that probably the completion callback on the android mediaplayer is arriving too late. I will see if I can reproduce it.

lakrsv commented 7 years ago

For your information, the pad in question is the Xiaomi Mi Pad 2

lakrsv commented 7 years ago

Can also reproduce the flicker on NVidia Shield

lakrsv commented 7 years ago

Here's a workaround: If you disable screen clearing the issue is still there in practice, but not visible anymore. The issue with this is that the moment you'd like to do something like fade the screen in / out and you do it when the video loops, you will still have a flicker.

//Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
 if (videoPlayer != null) {
            if (!videoPlayer.render()) {
                try {
                    videoPlayer.play(movieFile);
                } catch (FileNotFoundException e) {
                    videoPlayer = null;
                    Gdx.app.log("EXCEPTION", "Could not loop video", e);
                }
            }
        }

The limitation simply means nothing else can happen on the screen while you're playing the video.

SimonIT commented 3 years ago

Could you try if the issue persists with the newest snapshot? I've added a setLooping method to let the own media player of android loop the video. So the issue shouldn't persist anymore