java - 在 java swing 中播放 avi 视频文件

标签 java swing video user-interface avi

<分区>

我需要播放 avi 视频文件并将其添加到 jpanel。我需要做的就是从头到尾播放视频,然后继续我的程序。我不需要任何搜索功能或类似的功能。最简单的方法是什么?如果可能,最好不要使用 xuggler

最佳答案

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

关于java - 在 java swing 中播放 avi 视频文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16962013/

相关文章:

java - 无法使用 PowerMockRunner 运行 JUnit 测试

java - 如何将半透明 JWindow 上的鼠标事件传递到下面的 JFrame?

java - 使用类的普通方法调用 actionPerformed 方法

macos - 获取 Quicktime 视频信息

iphone - 如何禁用 UIImagePickerController 中视频的选择按钮

java - 配置 Ant 使用 JUnit 4

java - JAX-RS - 在 RESTful Web 服务中进行身份验证并获取用户数据

java - if、else if、else 语句的功能性和可读性

java - 如何删除 MigLayout 中的 JPanel 填充?

ios - 在 WatchOS 2 中从 URL 播放视频