使用vlcj从文件夹流式传输多个文件


    public void Stream(String FOLDER_PATH, int port){        
    File myDir = new File(FOLDER_PATH);
    File[] files = myDir.listFiles(); 
    if( myDir.exists() && myDir.isDirectory()){               
       do {                  
          System.out.println(files[i]+" ...");
          //File myFile = new File(files[i].getPath());                  
          mediaPlayer.playMedia(files[i].getPath(), 
          ":sout=#rtp{dst=127.0.0.1,port="+String.valueOf(port) +",mux=ts}",
          ":no-sout-rtp-sap", 
          ":no-sout-standard-sap", 
          ":sout-all", 
          ":sout-keep"
          ); 
          i++;
          }while(i< files.length && mediaPlayer.isMediaParsed());
      }    
}

如何修改此代码,使vlcj在当前文件结束后播放(流式播放(文件夹中的下一个文件?

我尝试了不同的方法,但在第一个文件之后就停止了。

如果您参考来自vlcj-1.2.0-test.jar分布的VLC样本uk.co.caprica.vlcj.test.list.TestMediaListEmbeddedPlayer,它就是这样做的:

/**
 * 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();
    }
}

相关内容

  • 没有找到相关文章

最新更新