在JavaSwing中播放avi视频文件

lmyy7pcs  于 2021-06-30  发布在  Java
关注(0)|答案(1)|浏览(491)

很难说出这里要问什么。这个问题模棱两可,含糊不清,不完整,过于宽泛,或者是修辞性的,不能以现在的形式得到合理的回答。有关澄清此问题以便重新打开的帮助,请访问帮助中心。
7年前关门了。
我需要播放一个avi视频文件,并将其添加到jpanel。我所需要做的就是从视频的开始播放到结束,然后继续我的节目。我不需要任何seek函数之类的。最简单的方法是什么?如果可能,最好不使用xuggler

htrmnn0y

htrmnn0y1#

使用vlcj很容易将vlc播放器嵌入到swing应用程序中。下面是一个工作示例:

public class PlayerPanel extends JPanel {

     private File vlcInstallPath = new File("D:/vlc");
     private EmbeddedMediaPlayer player;

     public PlayerPanel() {
         NativeLibrary.addSearchPath("libvlc", vlcInstallPath.getAbsolutePath());
         EmbeddedMediaPlayerComponent videoCanvas = new EmbeddedMediaPlayerComponent();
         this.setLayout(new BorderLayout());
         this.add(videoCanvas, BorderLayout.CENTER);
         this.player = videoCanvas.getMediaPlayer();
     }

     public void play(String media) {
         player.prepareMedia(media);
         player.parseMedia();
         player.play();
     }
 }

 class VideoPlayer extends JFrame {

     public VideoPlayer() {
          PlayerPanel player = new PlayerPanel();
          this.setTitle("Swing Video Player");
          this.setDefaultCloseOperation(EXIT_ON_CLOSE);
          this.setLayout(new BorderLayout());
          this.setSize(640, 480);
          this.setLocationRelativeTo(null);
          this.add(player, BorderLayout.CENTER);
          this.validate();
          this.setVisible(true);

          player.play("http://174.132.240.162:8000/;stream.nsv");
     }

      public static void main(String[] args) {
          new VideoPlayer();
      }
 }

相关问题