java 如何通过java控制VLC
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3768397/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to control VLC by java
提问by sajad
I want to run a program called VLCin java
and control it while running, for example if user clicked on ??or ??button, I do a specific suitable action.
我想运行一个被称为VLC中java
,如果用户点击上控制它在运行,例如??或??按钮,我做了具体的合适的动作。
I run VLC
by this code :
我VLC
用这个代码运行:
try
{
Runtime rt = Runtime.getRuntime();
Process p = rt.exec(VLCProgramAddFile + " udp://@:" + listeningPort);
OutputStream out = p.getOutputStream();
InputStream in = p.getInputStream();
p.waitFor();
System.out.println("End of VLC");
}
catch (Exception e)
{
System.out.println("error in running VLC");
}
I have heard about Java bindings, but I don't know how does it work for this job.
我听说过 Java 绑定,但我不知道它如何适用于这项工作。
采纳答案by Thirler
You are probably looking for VLCJ, this is a java wrapper for VLC. It allows you to embed VLC media player in a java application, and thus add all your personal controls.
您可能正在寻找 VLCJ,这是 VLC 的 Java 包装器。它允许您在 Java 应用程序中嵌入 VLC 媒体播放器,从而添加您的所有个人控件。
(Do note that for user applications this is fine, but the VLCJ library isn't perfect, you can have several problems pop up.)
(请注意,对于用户应用程序,这很好,但 VLCJ 库并不完美,您可能会弹出几个问题。)
EDIT: For my project I've seen memory leaks and issues with long running programs (multiple instances for several hours). Especially the multiple instances doesn't work in combination with some compile options (which are on by default).
编辑:对于我的项目,我已经看到内存泄漏和长时间运行程序的问题(几个小时的多个实例)。尤其是多个实例不能与某些编译选项(默认情况下启用)结合使用。
回答by Michael Berry
VLCjis what you're after yes - it's essentially a straight Java wrapper around libvlc. If you use it in process (especially if you use multiple players in process) you will sometimes see VM crashes - this isn't VLCJ's fault, rather libvlc and the native libraries it uses underneath have some subtle threading bugs that exposes these problems.
VLCj就是你所追求的——它本质上是一个围绕 libvlc 的直接 Java 包装器。如果您在进程中使用它(特别是如果您在进程中使用多个玩家),您有时会看到 VM 崩溃——这不是 VLCJ 的错,而是 libvlc 和它在下面使用的本机库有一些微妙的线程错误,这些错误暴露了这些问题。
You can get it working reliably with multiple instances, but to do so you need to use it out of process. See herefor my initial attempts at doing so. It's a bit of work to set up but once going, things seem to work very nicely.
您可以让它与多个实例一起可靠地工作,但要做到这一点,您需要在进程外使用它。请参阅此处了解我最初的尝试。设置起来有点麻烦,但是一旦开始,事情似乎就会很好地工作。
回答by Waldheinz
Depending on what you want to ultimately accomplish maybe the gstreamer Java bindingsare worth a look which will give you a very fine grained control about the playback. And you can do conversions and everything. They also have a minimalistic video player example application to get you started with.
根据您最终想要完成的任务,gstreamer Java 绑定可能值得一看,这将为您提供有关播放的非常细粒度的控制。你可以做转换和一切。他们还有一个简约的视频播放器示例应用程序,可以让您开始使用。