美好的一天同事们!
使用VLCJ和其他Java媒体API时遇到了一些问题。
1)我将一个简单的* .srt文件添加到我的EmbeddedMediaPlayerCompononent,bot怎么可能?
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);
}
}
答案 0 :(得分:3)
设置外部字幕文件:
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();
上有一大堆循序渐进的教程
答案 1 :(得分:1)
专注于"基本操作界面"问题的一个方面,请注意EmbeddedMediaPlayerComponent
扩展Panel
,一个AWT组件。因此,显示here的VLCJ覆盖示例覆盖paint()
。这个相关的独立example说明了在这种情况下的热门测试。