VLCJ中添加字幕和基本操作面板@Java
Add subtitle and basic operation panel in VLCJ @ Java
同事们大家好!
我在使用 VLCJ 和其他 Java 媒体 API-s 时遇到了一些问题。
1) 我会向我的 EmbeddedMediaPlayerCompononent 添加一个简单的 *.srt 文件,机器人,这怎么可能?
2) 另外,如何在 x64 Windows OS 中配置 VLC 库?
NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), "C:\Program Files (x86)\VideoLAN\VLC");
Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(),libVlc.class);
这不太好用。
3) 如何向我的 EmbeddedMediaPlayerCompononent 添加基本操作界面,如 pause/play 按钮?
谢谢,最诚挚的问候! :)
我的"VideoPlayer"class
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);
}
}
关注问题的 "basic operation interface" 方面,请注意 EmbeddedMediaPlayerComponent
extends Panel
, an AWT component. Accordingly, the VLCJ overlay example shown here overrides paint()
. This related, stand-alone example 说明了这种情况下的命中测试。
设置外挂字幕文件:
mediaPlayerComponent.getMediaPlayer().setSubTitleFile("whatever.srt");
如何添加 pause/play 按钮完全取决于您,它需要不是特定于 vlcj 的标准 Swing 代码。您将按钮添加到您的用户界面,然后 link 这些按钮通过使用事件侦听器与媒体播放器一起使用。例如,这是一种方式:
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();
上有一大堆循序渐进的教程
同事们大家好!
我在使用 VLCJ 和其他 Java 媒体 API-s 时遇到了一些问题。
1) 我会向我的 EmbeddedMediaPlayerCompononent 添加一个简单的 *.srt 文件,机器人,这怎么可能?
2) 另外,如何在 x64 Windows OS 中配置 VLC 库?
NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), "C:\Program Files (x86)\VideoLAN\VLC");
Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(),libVlc.class);
这不太好用。
3) 如何向我的 EmbeddedMediaPlayerCompononent 添加基本操作界面,如 pause/play 按钮?
谢谢,最诚挚的问候! :)
我的"VideoPlayer"class
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);
}
}
关注问题的 "basic operation interface" 方面,请注意 EmbeddedMediaPlayerComponent
extends Panel
, an AWT component. Accordingly, the VLCJ overlay example shown here overrides paint()
. This related, stand-alone example 说明了这种情况下的命中测试。
设置外挂字幕文件:
mediaPlayerComponent.getMediaPlayer().setSubTitleFile("whatever.srt");
如何添加 pause/play 按钮完全取决于您,它需要不是特定于 vlcj 的标准 Swing 代码。您将按钮添加到您的用户界面,然后 link 这些按钮通过使用事件侦听器与媒体播放器一起使用。例如,这是一种方式:
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();
上有一大堆循序渐进的教程