Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigate inconsistent behaviour around stopping/finished and playing next item #1133

Open
caprica opened this issue Apr 10, 2022 · 2 comments

Comments

@caprica
Copy link
Owner

caprica commented Apr 10, 2022

For a long time, the idiom in vlcj to play multiple media one after the other was to wait for a finished event, then start playing the next media in the finished handler.

With a recent change to 4.x of VLC, the "end reached" event used by vlcj became instead "stopping".

The event sequence should be:

  • playing
  • stopping
  • stopped
  • playing
  • stopping
  • stopped
  • -playing
  • ...etc...

Now, following that same idiom the events are inconsistently (a race):

  • playing
  • stopping
  • playing
  • stopping
  • playing
  • ...etc...

So the stopped event does not fire.

In theory, the fix is just to move "finished" processing to "stop" - making sure not to request new media until after a stopped event is received.

@caprica
Copy link
Owner Author

caprica commented Apr 10, 2022

Demonstration of issue, toggle the boolean "bug" to switch behaviours:

import uk.co.caprica.vlcj.player.base.MediaPlayer;
import uk.co.caprica.vlcj.player.base.OneShotMediaPlayerEventListener;
import uk.co.caprica.vlcj.player.component.EmbeddedMediaPlayerComponent;

import javax.swing.JFrame;
import java.util.concurrent.atomic.AtomicInteger;

public class EventTest {

    private static EmbeddedMediaPlayerComponent mediaPlayerComponnt;

    private static final AtomicInteger counter = new AtomicInteger(0);

    private static final boolean bug = true;

    private static final String MEDIA_1 = "movie1.mp4";
    private static final String MEDIA_2 = "movie2.mp4";

    public static void main(String[] args) {
        mediaPlayerComponnt = new EmbeddedMediaPlayerComponent() {
            @Override
            public void playing(MediaPlayer mediaPlayer) {
                System.out.printf("%02d PLAYING%n", counter.incrementAndGet());
            }

            @Override
            public void stopped(MediaPlayer mediaPlayer) {
                System.out.printf("%02d STOPPED, BUG IS %s%n", counter.incrementAndGet(), bug);
                if (!bug) {
                    mediaPlayer.submit(() -> {
                        mediaPlayer.media().play(MEDIA_2);
                    });
                }
            }

            @Override
            public void stopping(MediaPlayer mediaPlayer) {
                System.out.printf("%02d STOPPING, BUG IS %s%n", counter.incrementAndGet(), bug);
                if (bug) {
                    mediaPlayer.submit(() -> {
                        mediaPlayer.media().play(MEDIA_2);
                    });
                }
            }
        };

        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setContentPane(mediaPlayerComponnt);
        f.setSize(800, 600);
        f.setVisible(true);

        mediaPlayerComponnt.mediaPlayer().events().addMediaPlayerEventListener(new OneShotMediaPlayerEventListener() {
            @Override
            public void playing(MediaPlayer mediaPlayer) {
                mediaPlayer.controls().setPosition(0.99f);
                done(mediaPlayer);
            }
        });

        mediaPlayerComponnt.mediaPlayer().media().play(MEDIA_1);
    }
}

@caprica
Copy link
Owner Author

caprica commented Jan 13, 2023

There was some discussion a while ago now at the VLC GitLab issues, but nothing has changed so far.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant