当前位置: 首页 > 工具软件 > vlcj > 使用案例 >

vlcj loop

仲孙温文
2023-12-01

If you refer to VLC sample uk.co.caprica.vlcj.test.list.TestMediaListEmbeddedPlayer from vlcj-1.2.0-test.jar distribution, this is how it is done:

/**
 * Example showing how to combine a media list player with an embedded media
 * player.
 */
public class TestMediaListEmbeddedPlayer extends 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();
    }
}
 类似资料:

相关阅读

相关文章

相关问答