在Java swing中播放avi视频文件 [英] play an avi video file in java swing

查看:167
本文介绍了在Java swing中播放avi视频文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要播放一个avi视频文件并将其添加到jpanel中.我需要做的就是从视频的开头到结尾播放,然后继续执行我的程序.我不需要任何查找功能或类似的东西.最简单的方法是什么?尽可能不使用xuggler

I need to play an avi video file and add it to a jpanel. All I need to be able to do is to play from beginning to end of the video and then proceed with my program. I don't need any seek functions or anything like that. What is the simplest way of doing this? preferbly without using xuggler if possible

推荐答案

使用

It easy to embed the VLC player inside a swing application using VLCJ. Here is a working example:

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

这篇关于在Java swing中播放avi视频文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆