mesh
mesh

Reputation: 65

How to prepare playlist using "MediaPlayer" in vlcj?

I'm making desktop application using java swing and vlcj. I play playlist using MediaListPlayer class but I want to do it using MediaPlayer class in vlcj. How to play playlist using MediaPlayer class (without MediaListPlayer)? Thanks.

Upvotes: 2

Views: 908

Answers (1)

caprica
caprica

Reputation: 4146

If you want to use a playlist, instead of MediaPlayer use MediaListPlayer.

The MediaListPlayer component provides access to a MediaPlayer, and provides additional methods specifically for dealing with the playlist.

You can also use AudioListPlayerComponent or EmbeddedMediaListPlayerComponent to make things a bit easier.

There is a complete minimal example in the vlcj project at GitHub here:

https://github.com/caprica/vlcj/blob/vlcj-4.x/src/test/java/uk/co/caprica/vlcj/test/component/BasicEmbeddedMediaListPlayerComponentTest.java

The MediaListComponent has methods for dealing with the playlist, for example:

mediaListPlayerComponent.mediaListPlayer().list().media().add("/home/music/some-cool-synthwave-tune.mp3");
mediaListPlayerComponent.mediaListPlayer().list().media().add("/home/music/another-cool-synthwave-tune.mp3");
mediaListPlayerComponent.mediaListPlayer().list().media().add("/home/music/synthwave-is-the-best.mp3");

mediaListPlayerComponent.mediaListPlayer().controls().play();

If you need to get the underlying MediaPlayer, do something like this:

long length = mediaListPlayerComponent.mediaPlayer().status().length()

The return value from that mediaPlayer() method is the 'regular' vlcj MediaPlayer that you are referring to in your question.

But you should first check the methods on the MediaListPlayer to see if they are better for what you need.

You can implement your own playlist using the regular vlcj MediaPlayer - you simply need to add a MediaPlayerEventListener to handle stopped or finished events and on receipt of such an event play the next media.

With upcoming VLC 4.x, I think this is right, using the MediaListPlayer would be necessary if you need gapless playback.

Upvotes: 2

Related Questions