在 Mac 上使用 vlcj 播放视频
Play a video with vlcj on a Mac
您好,我正在尝试在 mac 上获取视频 运行 vlcj。
我尝试了几件事,但到处都有问题。
程序正在启动,但没有视频播放。有谁知道如何在 mac 上处理 vlcj?
我的意图是在 mac 和 java 上播放 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.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.access0(EventQueue.java:97)
at java.awt.EventQueue.run(EventQueue.java:709)
at java.awt.EventQueue.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain.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)
这是 OSX 上 JDK 晚于 1.6 的 vlcj(实际上还有其他应用程序)的一个众所周知且有据可查的问题。
我知道 link- 只有答案不是最好的,但是关于这个问题的信息太多了,无法在这里重复,所以请检查 https://github.com/caprica/vlcj/issues/205。
基本上您不能使用嵌入式媒体播放器组件,因为它依赖于重量级 AWT 组件(Canvas
)来 'host' 视频,在 JDK 1.7 和稍后 OSX 不再有重量级 AWT。
所以 OSX 要么使用所谓的 "direct" 渲染方法和 vlcj,要么使用 JDK 1.6.
谢谢
这是一步一步解释的一切
http://capricasoftware.co.uk/#/projects/vlcj/tutorial/direct-rendering
如果您可以延迟 3 秒,则 rtsp 流工作得很好
您好,我正在尝试在 mac 上获取视频 运行 vlcj。 我尝试了几件事,但到处都有问题。 程序正在启动,但没有视频播放。有谁知道如何在 mac 上处理 vlcj? 我的意图是在 mac 和 java 上播放 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.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.access0(EventQueue.java:97)
at java.awt.EventQueue.run(EventQueue.java:709)
at java.awt.EventQueue.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain.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)
这是 OSX 上 JDK 晚于 1.6 的 vlcj(实际上还有其他应用程序)的一个众所周知且有据可查的问题。
我知道 link- 只有答案不是最好的,但是关于这个问题的信息太多了,无法在这里重复,所以请检查 https://github.com/caprica/vlcj/issues/205。
基本上您不能使用嵌入式媒体播放器组件,因为它依赖于重量级 AWT 组件(Canvas
)来 'host' 视频,在 JDK 1.7 和稍后 OSX 不再有重量级 AWT。
所以 OSX 要么使用所谓的 "direct" 渲染方法和 vlcj,要么使用 JDK 1.6.
谢谢
这是一步一步解释的一切 http://capricasoftware.co.uk/#/projects/vlcj/tutorial/direct-rendering
如果您可以延迟 3 秒,则 rtsp 流工作得很好