vlcj MediaPlayer: how to detect when video has finished playing

4.2k views Asked by At

I'm playing a video file (full screen) and I want an audio file to play once the video has finished playing.

The thing is:

  • I'm able to play a video file in full screen;
  • I'm able to detect when the video file has finished playing:

    while(!mpu.getMediaPlayer().getMediaPlayerState().toString().equalsIgnoreCase("libvlc_Ended"))
    {
        System.out.println("It's being played");
        estado = mpu.getMediaPlayer().getMediaPlayerState();           
    }
    
  • But those lines make my video leave it's full screen....

I need the video file to keep at full screen.

1

There are 1 answers

0
caprica On

If you want to (as per the question title) detect when the video has finished playing, you should use an event listener - you should not use a tight-loop that queries the media player state, so use:

mpu.getMediaPlayer().addMediaPlayerEventListener(new MediaPlayerEventAdapter() {
    @Override
    public void finished(MediaPlayer mediaPlayer) {
        // Code to execute here when media player finished playing...
    }
});

If you want to play another media file (in your case an audio file) after your first video finishes then you might like to consider using an EmbeddedMediaListPlayerComponent which will take care of playing a play-list for you.

Using an EmbeddedMediaListPlayerComponent is just a different approach that might work for you, but there is nothing wrong either with using an event listener to manage your own play-list.

The remainder of your question asks about full-screen behaviours.

There is nothing in the code you have posted so far that would cause the media player to exit full-screen so something else, that you have not posted, in your code is going wrong.

You probably need to post more code to show how exactly you are implementing full-screen - in particular you have not so far shown how you are embedding the media player in your application and how precisely you are entering full-screen mode.

There are also many examples in the vlcj test sources that demonstrate play-lists, events, and full-screen on all platforms that you should review.