您好我试图在Mac上使用vlcj运行视频。 我尝试了几件事,但到处都有问题。 该程序正在启动,但没有视频播放。有谁知道如何在mac上处理vlcj? 我的意图是使用java在mac上播放rtsp流。我首先尝试使用opencv和现在的vlcj,但没有成功。
有没有很好的例子如何在Mac上执行此操作,或者有人知道它为什么不起作用吗?
由于
代码:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
import uk.co.caprica.vlcj.binding.LibVlc;
import uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent;
import uk.co.caprica.vlcj.runtime.RuntimeUtil;
import com.sun.jna.Native;
import com.sun.jna.NativeLibrary;
public class VideoExample {
private final EmbeddedMediaPlayerComponent mediaPlayerComponent;
public static void main(final String[] args) {
uk.co.caprica.vlcj.binding.LibC.INSTANCE.setenv("VLC_PLUGIN_PATH", "/Applications/VLC.app/Contents/MacOS/plugins", 1);
NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), "/Applications/VLC.app/Contents/MacOS/lib");
Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
new VideoExample(args);
}
});
}
private VideoExample(String[] args) {
JFrame frame = new JFrame("vlcj Tutorial");
mediaPlayerComponent = new EmbeddedMediaPlayerComponent();
frame.setContentPane(mediaPlayerComponent);
frame.setLocation(100, 100);
frame.setSize(500, 500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
mediaPlayerComponent.getMediaPlayer().playMedia("/test.m4v");
}
}
错误:
[main] INFO uk.co.caprica.vlcj.Info - vlcj: <version not available>
[main] INFO uk.co.caprica.vlcj.Info - java: 1.8.0_45 Oracle Corporation
[main] INFO uk.co.caprica.vlcj.Info - java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre
[main] INFO uk.co.caprica.vlcj.Info - os: Mac OS X 10.10.4 x86_64
[AWT-EventQueue-0] INFO uk.co.caprica.vlcj.binding.LibVlcFactory - vlc: 2.2.1 Terry Pratchett (Weatherwax), changeset 2.2.1-0-ga425c42
[AWT-EventQueue-0] INFO uk.co.caprica.vlcj.binding.LibVlcFactory - libvlc: /Applications/VLC.app/Contents/MacOS/lib/libvlc.dylib
JavaVM WARNING: JAWT_GetAWT must be called after loading a JVM
Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: Can't load JAWT
at com.sun.jna.Native.getWindowHandle0(Native Method)
at com.sun.jna.Native$AWT.getComponentID(Native.java:1879)
at com.sun.jna.Native.getComponentID(Native.java:253)
at uk.co.caprica.vlcj.player.embedded.videosurface.CanvasVideoSurface.attach(CanvasVideoSurface.java:76)
at uk.co.caprica.vlcj.player.embedded.DefaultEmbeddedMediaPlayer.attachVideoSurface(DefaultEmbeddedMediaPlayer.java:162)
at uk.co.caprica.vlcj.player.embedded.DefaultEmbeddedMediaPlayer.onBeforePlay(DefaultEmbeddedMediaPlayer.java:327)
at uk.co.caprica.vlcj.player.DefaultMediaPlayer.play(DefaultMediaPlayer.java:804)
at uk.co.caprica.vlcj.player.DefaultMediaPlayer.playMedia(DefaultMediaPlayer.java:265)
at uk.co.caprica.vlcj.player.DefaultMediaPlayer.playMedia(DefaultMediaPlayer.java:256)
at VideoExample.<init>(VideoExample.java:46)
at VideoExample.<init>(VideoExample.java:34)
at VideoExample$1.run(VideoExample.java:29)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:756)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:726)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
答案 0 :(得分:2)
这是OSX上vlcj(实际上是其他应用程序)的一个众所周知且记录良好的问题,JDK的版本高于1.6。
我知道仅限链接的答案并不是最好的,但有关此问题的信息太多,请在此处重复,因此请检查https://github.com/caprica/vlcj/issues/205。
基本上你不能使用嵌入式媒体播放器组件,因为它依赖于一个重量级的AWT组件(Canvas
)到主机&#39;视频,在OSX上的JDK 1.7及更高版本中,不再有重量级的AWT。
所以在OSX上要么使用所谓的&#34;直接&#34;使用vlcj进行渲染,或使用JDK 1.6。
答案 1 :(得分:0)
由于
以下是一步一步解释的一切 http://capricasoftware.co.uk/#/projects/vlcj/tutorial/direct-rendering
如果你没有3秒延迟,rtsp流可以正常工作