-->

Java Vlcj - How to change media in EmbbededMediaPl

2019-08-22 12:40发布

问题:

So I have a EmbbededMediaPlayerComponent and Javafx list full of urls which can be played in EmbbededMediaPlayerComponent. The one on which you click is then supposed to be played in EmbbededMediaPlayerComponent. The first url you choose works just fine and is displayed in the player. The thing is, after I choose another url I want the first one to be replaced with the second one. What is the correct way to dispose the first media and then play the second one?

回答1:

I'm not sure if it's the "correct" way to do it but I would do:

EmbeddedMediaPlayerComponent.getMediaPLayer().playMedia(mrlToMedia);

If I have understood correctly this should just load the next file and start playing that one.

It's also possible to use

EmbeddedMediaPlayerComponent.getMediaPLayer().startMedia(String mrl);

which should try to start the playback with the difference that this is a blocking operation untill playback has started.

Also possible to do

EmbeddedMediaPlayerComponent.getMediaPLayer().prepareMedia(String mrl);
EmbeddedMediaPlayerComponent.getMediaPLayer().start();

This is the same as the one above but in two steps.



回答2:

All you need to do is this:

mediaPlayerComponent.getMediaPlayer().playMedia(mrl);

Which should be exactly the same as how you played your initial media.



标签: java javafx vlcj