VLCJ@Java中添加字幕和基本操作面板

Posted

技术标签:

【中文标题】VLCJ@Java中添加字幕和基本操作面板【英文标题】:Add subtitle and basic operation panel in VLCJ @ Java 【发布时间】:2015-03-21 18:36:41 【问题描述】:

同事们好!

我在使用 VLCJ 和其他 Java 媒体 API-s 时遇到了一些问题。

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 中添加基本操作界面,例如暂停/播放按钮?

谢谢你,最好的问候! :)

我的“视频播放器”课程

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

【问题讨论】:

【参考方案1】:

设置外部字幕文件:

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 有一大堆分步教程

【讨论】:

【参考方案2】:

关注您问题的“基本操作界面”方面,注意EmbeddedMediaPlayerComponent 扩展了Panel,一个AWT 组件。因此,here 所示的 VLCJ 覆盖示例将覆盖paint()。这个相关的独立 example 说明了在这种情况下的命中测试。

【讨论】:

以上是关于VLCJ@Java中添加字幕和基本操作面板的主要内容,如果未能解决你的问题,请参考以下文章

短视频运营短视频剪辑 ③ ( 添加字幕 | 智能识别字幕 | 修改字幕 | 字幕预设 | 字幕换行 | 使用字幕作为封面主题 )

pr2017 中字幕的矩形工具如何输入文字

android ffmpeg视频添加字幕和配音

PS CS6视频剪辑基本技巧视频剪接和添加图片

vue怎么加滚动的字幕

vue滚动字幕怎样添加