使用vlcj创建媒体播放器时无法创建本机媒体资源

时间:2015-05-28 18:55:31

标签: java vlcj

我正在使用vlcj构建媒体播放器?当我运行代码时,gui打开正常,但视频无法播放。

//检查本机路径

    NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), NATIVE_LIBRARY_SEARCH_PATH);
    System.out.println(LibVlc.INSTANCE.libvlc_get_version());
    }

    // Swing part
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            new Tutorial(args);
        }
    });



        mediaPlayerComponent.getMediaPlayer().addMediaPlayerEventListener(new MediaPlayerEventAdapter() {
            @Override
            public void playing(MediaPlayer mediaPlayer) {
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        frame.setTitle(String.format(
                            "My First Media Player - %s",
                              mediaPlayerComponent.getMediaPlayer().getMediaMeta().getTitle()
                        ));
                    }
                });
            }

            public void finished(MediaPlayer mediaPlayer) {
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        closeWindow();
                    }
                });
            }


            public void error(MediaPlayer mediaPlayer) {
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        JOptionPane.showMessageDialog(
                            frame,
                            "Failed to play media",
                            "Error",
                            JOptionPane.ERROR_MESSAGE
                        );
                        closeWindow();
                    }
                });
            }
        });

        frame.setContentPane(contentPane);
        frame.setVisible(true);

        mediaPlayerComponent.getMediaPlayer().playMedia(args[0]);
    }

我收到以下错误。

9 [main] INFO uk.co.caprica.vlcj.Info - vlcj:3.7.0 9 [主要] INFO uk.co.caprica.vlcj.Info - java:1.8.0_31 Oracle Corporation 9 [main] INFO uk.co.caprica.vlcj.Info - java home:C:\ Program Files \ Java \ jre1.8.0_31 9 [主要] INFO uk.co.caprica.vlcj.Info - os:Windows 8.1 6.3 amd64 932 [main] INFO uk.co.caprica.vlcj.discovery.NativeDiscovery - 发现在'C:\ Program Files \ VideoLAN \ VLC'找到了libvlc 真正 2.2.1 Terry Pratchett(Weatherwax)

1367 [AWT-EventQueue-0] INFO uk.co.caprica.vlcj.binding.LibVlcFactory - vlc:2.2.1 Terry Pratchett(Weatherwax),变更集2.2.1-0-ga425c42

1367 [AWT-EventQueue-0] INFO uk.co.caprica.vlcj.binding.LibVlcFactory - libvlc:C:\ Program Files \ VideoLAN \ VLC \ libvlc.dll

2061 [AWT-EventQueue-0]错误uk.co.caprica.vlcj.player.DefaultMediaPlayer - 无法为'SimpleMedia创建本机媒体资源[mrl = C:/Users/venkatneehar/Downloads/1.mpg,mediaOptions = [Ljava.lang.String; @ a420335]'

1 个答案:

答案 0 :(得分:1)

您的MRL(文件名)在Windows上使用正斜杠。

由于跨平台兼容性,Java在Windows上接受正斜杠,但在将文件名传递给使用本机函数调用来打开文件的VLC时,它不起作用。

因此,使用带有反斜杠的“正确”Windows文件名,它将起作用。