同事们,美好的一天!

使用VLCJ和其他Java媒体API时遇到了一些麻烦。

1)我会向我的EmbeddedMediaPlayerCompononent添加一个简单的* .srt文件,这怎么可能?

2)另外,如何在x64 Windows操作系统中配置VLC库?

NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), "C:\\Program Files (x86)\\VideoLAN\\VLC");
                    Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(),libVlc.class);


这行不通。

3)我怎样才能向我的EmbeddedMediaPlayerCompononent添加基本操作界面,例如暂停/播放按钮?

谢谢您最好的问候! :)

我的“ VideoPlayer”课程

    package GUI.MediaPlayer;
    import java.awt.BorderLayout;
    import java.io.IOException;

    import javax.swing.JFrame;
    import javax.swing.JOptionPane;

    import uk.co.caprica.vlcj.binding.LibVlc;
    import uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent;
    import uk.co.caprica.vlcj.runtime.RuntimeUtil;
    import StreamBean.UIBean;

    import com.sun.jna.Native;
    import com.sun.jna.NativeLibrary;

    public class VideoPlayer extends JFrame{
        private final EmbeddedMediaPlayerComponent mediaPlayerComponent;
        public VideoPlayer(String videoURL) {

            String os = System.getProperty("os.name").toLowerCase();

            if(os.startsWith("win")){
                String registrytype = System.getProperty("sun.arch.data.model");
                System.out.println("a rendszered : " +os+" - " +registrytype+ " bites");
                if(registrytype.contains("32")){
                    //Windows 32 bites verzió
                    System.out.println("Belépett a 32-be");
                    NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), "C:\\Program Files\\VideoLAN\\VLC");
                    Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);
                }else if(registrytype.contains("64")){
                    //Windows 64 bites verzió
                    System.out.println("Belépett a 64-be");
                    NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), "C:\\Program Files (x86)\\VideoLAN\\VLC");
                    Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);
                }else{
                    JOptionPane.showMessageDialog(null, "Kérem előbb telepítse a VLC lejátszót.");
                }

            }
            if(os.startsWith("mac")){
                //Mac OSX kiadáshoz
                NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), "/Applications/VLC.app/Contents/MacOS/lib/");
                Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);
            }

            this.setTitle("Aktuális videó");
            this.setLayout(new BorderLayout());

            mediaPlayerComponent = new EmbeddedMediaPlayerComponent();

            this.add(mediaPlayerComponent,BorderLayout.CENTER);

            this.setDefaultCloseOperation(this.DISPOSE_ON_CLOSE);
                        //set the Jframe - this - resolution to the screen resoltuion
            new UIBean().setWindowSize(this);
            this.setVisible(true);

            mediaPlayerComponent.getMediaPlayer().playMedia(videoURL);
        }
    }

最佳答案

设置外部字幕文件:

mediaPlayerComponent.getMediaPlayer().setSubTitleFile("whatever.srt");


如何添加暂停/播放按钮完全取决于您,它需要标准的Swing代码,而该代码并非vlcj特有的。您将按钮添加到用户界面,然后使用事件侦听器将这些按钮与媒体播放器链接起来。例如,这是一种方法:

JButton playButton = new JButton("Play/Pause");
playButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent evt) {
        mediaPlayerComponent.getMediaPlayer.pause();
    }
});


有很多原因可能导致找不到本地库的原因,但是NativeLibrary.addSearchPath(...)确实可以工作。您必须确保匹配JVM和VLC安装的CPU体系结构(32位JVM需要32位VLC,64位JVM需要64位VLC)。在大多数情况下,您应该使用:

new NativeDiscovery().discover();


http://capricasoftware.co.uk/#/projects/vlcj/tutorial上有很多分步教程

10-07 19:42
查看更多