gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 07:02:19 25 4
gpt4 key购买 nike

同事们好!

我在使用 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");

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

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

可能无法找到 native 库的原因有很多,但 NativeLibrary.addSearchPath(...) 肯定确实有效。您必须确保您的 JVM 和 VLC 安装的 CPU 架构相匹配(32 位 JVM 需要 32 位 VLC,64 位 JVM 需要 64 位 VLC)。在大多数情况下,您应该只使用:

new NativeDiscovery().discover();

http://capricasoftware.co.uk/#/projects/vlcj/tutorial 上有一大堆循序渐进的教程。

关于java - VLCJ @ Java 添加字幕和基本操作面板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29186517/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com