gpt4 book ai didi

java - 使用 VLCJ 播放文件序列

转载 作者:行者123 更新时间:2023-11-30 01:43:53 24 4
gpt4 key购买 nike

第一次使用VLCJ。我可以播放一个文件,但我需要连续播放多个文件。我意识到有一个用于 mediaEnded 的 EventListener,但我不知道如何使用它...我对 Java 有点陌生,这是我第一次使用 GUI。我想我只需要帮助设置监听器,我可以自己将其连接到我的程序。任何帮助,将不胜感激。如果有帮助,我将使用 EmbeddedMediaPlayerComponent 来播放文件。谢谢您

最佳答案

在 VLCJ 示例中找到解决方案

公共(public)类 TestMediaListEmbeddedPlayer 扩展了 VlcjTest {

public static void main(String[] args) throws Exception {
MediaPlayerFactory mediaPlayerFactory = new MediaPlayerFactory();

Canvas canvas = new Canvas();
canvas.setBackground(Color.black);
CanvasVideoSurface videoSurface = mediaPlayerFactory.newVideoSurface(canvas);

EmbeddedMediaPlayer mediaPlayer = mediaPlayerFactory.newEmbeddedMediaPlayer();
mediaPlayer.setVideoSurface(videoSurface);

MediaListPlayer mediaListPlayer = mediaPlayerFactory.newMediaListPlayer();

mediaListPlayer.addMediaListPlayerEventListener(new MediaListPlayerEventAdapter() {
@Override
public void nextItem(MediaListPlayer mediaListPlayer, libvlc_media_t item, String itemMrl) {
System.out.println("nextItem()");
}
});

mediaListPlayer.setMediaPlayer(mediaPlayer); // <--- Important, associate the media player with the media list player

JPanel cp = new JPanel();
cp.setBackground(Color.black);
cp.setLayout(new BorderLayout());
cp.add(canvas, BorderLayout.CENTER);

JFrame f = new JFrame("vlcj embedded media list player test");
f.setIconImage(new ImageIcon(TestMediaListEmbeddedPlayer.class.getResource("/icons/vlcj-logo.png")).getImage());
f.setContentPane(cp);
f.setSize(800, 600);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);

MediaList mediaList = mediaPlayerFactory.newMediaList();
String[] options = {};
mediaList.addMedia("C:\\Documents and Settings\\DEVELOPER\\Desktop\\videoplayback1.mp4", options);
mediaList.addMedia("C:\\Documents and Settings\\DEVELOPER\\Desktop\\videoplayback2.mp4", options);

mediaListPlayer.setMediaList(mediaList);
mediaListPlayer.setMode(MediaListPlayerMode.LOOP);

mediaListPlayer.play();

// This looping is just for purposes of demonstration, ordinarily you would
// not do this of course
for(;;) {
Thread.sleep(500);
mediaPlayer.setChapter(3);

Thread.sleep(5000);
mediaListPlayer.playNext();
}

// mediaList.release();
// mediaListPlayer.release();
// mediaPlayer.release();
// mediaPlayerFactory.release();
}

}

关于java - 使用 VLCJ 播放文件序列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58917545/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com