我正在尝试编写一个用于Java Swing应用程序的基本VLC播放器。我主要关注vlcj网站上的教程:http://capricasoftware.co.uk/#/projects/vlcj/tutorial/my-first-media-player
到目前为止,这是我的代码:
import uk.co.caprica.vlcj.discovery.NativeDiscovery;
import uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
public class VideoPlayer {
private final JFrame frame;
private final EmbeddedMediaPlayerComponent mediaPlayerComponent;
public static void main(String[] args) {
new NativeDiscovery().discover();
SwingUtilities.invokeLater(new Runnable(){
@Override
public void run(){
new VideoPlayer();
}
});
}
public VideoPlayer(){
frame=new JFrame("My First Media Player");
frame.setBounds(100,100,600,400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mediaPlayerComponent = new EmbeddedMediaPlayerComponent();
frame.setContentPane(mediaPlayerComponent);
frame.setVisible(true);
}
}
我设法让vlc库看似加载,但是一旦我开始尝试将媒体播放器嵌入到JFrame中,我在打印输出中出现以下错误:
run:
_ _
__ _| | ___ (_)
\ \ / / |/ __|| |
\ V /| | (__ | |
\_/ |_|\___|/ | 2.1.0
|__/ www.capricasoftware.co.uk
VLCJ is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
VLCJ is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with VLCJ. If not, see <http://www.gnu.org/licenses/>.
Copyright 2009, 2010, 2011, 2012 Caprica Software Limited.
Exception in thread "AWT-EventQueue-0" java.lang.AbstractMethodError: com.sun.jna.Structure.getFieldOrder()Ljava/util/List;
at com.sun.jna.Structure.fieldOrder(Structure.java:831)
at com.sun.jna.Structure.getFields(Structure.java:857)
at com.sun.jna.Structure.deriveLayout(Structure.java:983)
at com.sun.jna.Structure.calculateSize(Structure.java:908)
at com.sun.jna.Structure.calculateSize(Structure.java:896)
at com.sun.jna.Structure.allocateMemory(Structure.java:357)
at com.sun.jna.Structure.<init>(Structure.java:191)
at com.sun.jna.Structure.<init>(Structure.java:180)
at com.sun.jna.Structure.<init>(Structure.java:167)
at com.sun.jna.Structure.<init>(Structure.java:159)
at uk.co.caprica.vlcj.binding.internal.media_meta_changed.<init>(media_meta_changed.java:27)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.lang.Class.newInstance(Class.java:442)
at com.sun.jna.Structure.newInstance(Structure.java:1491)
at com.sun.jna.Native.getNativeSize(Native.java:984)
at com.sun.jna.Structure.getNativeSize(Structure.java:1769)
at com.sun.jna.Structure.getNativeSize(Structure.java:1762)
at com.sun.jna.Structure.validateField(Structure.java:958)
at com.sun.jna.Structure.validateFields(Structure.java:972)
at com.sun.jna.Structure.<init>(Structure.java:186)
at com.sun.jna.Structure.<init>(Structure.java:180)
at com.sun.jna.Structure.<init>(Structure.java:167)
at com.sun.jna.Structure.<init>(Structure.java:159)
at com.sun.jna.Union.<init>(Union.java:37)
at uk.co.caprica.vlcj.binding.internal.libvlc_event_u.<init>(libvlc_event_u.java:24)
at uk.co.caprica.vlcj.binding.internal.libvlc_event_u$ByValue.<init>(libvlc_event_u.java:26)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.lang.Class.newInstance(Class.java:442)
at com.sun.jna.Structure.newInstance(Structure.java:1491)
at com.sun.jna.Native.getNativeSize(Native.java:984)
at com.sun.jna.Structure.getNativeSize(Structure.java:1769)
at com.sun.jna.Structure.getNativeSize(Structure.java:1762)
at com.sun.jna.Structure.validateField(Structure.java:958)
at com.sun.jna.Structure.validateFields(Structure.java:972)
at com.sun.jna.Structure.<init>(Structure.java:186)
at com.sun.jna.Structure.<init>(Structure.java:180)
at com.sun.jna.Structure.<init>(Structure.java:167)
at com.sun.jna.Structure.<init>(Structure.java:159)
at uk.co.caprica.vlcj.binding.internal.libvlc_event_t.<init>(libvlc_event_t.java:28)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.lang.Class.newInstance(Class.java:442)
at com.sun.jna.Structure.newInstance(Structure.java:1491)
at com.sun.jna.CallbackReference.getNativeType(CallbackReference.java:234)
at com.sun.jna.CallbackReference.<init>(CallbackReference.java:209)
at com.sun.jna.CallbackReference.getFunctionPointer(CallbackReference.java:386)
at com.sun.jna.CallbackReference.getFunctionPointer(CallbackReference.java:368)
at com.sun.jna.Function.convertArgument(Function.java:496)
at com.sun.jna.Function.invoke(Function.java:258)
at com.sun.jna.Library$Handler.invoke(Library.java:218)
at com.sun.proxy.$Proxy1.libvlc_event_attach(Unknown Source)
at uk.co.caprica.vlcj.player.DefaultMediaPlayer.registerEventListener(DefaultMediaPlayer.java:1558)
at uk.co.caprica.vlcj.player.DefaultMediaPlayer.createInstance(DefaultMediaPlayer.java:1508)
at uk.co.caprica.vlcj.player.DefaultMediaPlayer.<init>(DefaultMediaPlayer.java:168)
at uk.co.caprica.vlcj.player.embedded.DefaultEmbeddedMediaPlayer.<init>(DefaultEmbeddedMediaPlayer.java:133)
at uk.co.caprica.vlcj.player.MediaPlayerFactory.newEmbeddedMediaPlayer(MediaPlayerFactory.java:414)
at uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent.<init>(EmbeddedMediaPlayerComponent.java:161)
at VideoPlayer.<init>(VideoPlayer.java:27)
at VideoPlayer$1.run(VideoPlayer.java:17)
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$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:76)
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)
BUILD SUCCESSFUL (total time: 2 seconds)`
我使用的是Windows 10,并且一直在使用64位版本的Netbeans和VLC。我使用的是3.5版JNA和JNA平台,以及VLCJ 2.1.0。
从我在堆栈溢出和其他站点上看到的情况来看,当兼容性出现问题时,会出现这些类型的错误。我不知道我做错了什么,据我所知,我正在使用每个元素的所有正确版本。
我对编码很新,所以可能错过了一些基本的东西,但很多人提前感谢你们给出的任何建议!
编辑:
不知道为什么,但我使用的是与我的其他库不兼容的旧版VLCJ。
我现在更新了我的库以使用VLCJ 3.10和JNA 4.1.0。但是现在代码在VLC甚至初始化之前就被困在其他地方了:
Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/LoggerFactory
at uk.co.caprica.vlcj.Info.<init>(Info.java:37)
at uk.co.caprica.vlcj.Info.<init>(Info.java:32)
at uk.co.caprica.vlcj.Info$InfoHolder.<clinit>(Info.java:47)
at uk.co.caprica.vlcj.Info.getInstance(Info.java:56)
at uk.co.caprica.vlcj.discovery.NativeDiscovery.<clinit>(NativeDiscovery.java:58)
at VideoPlayer.main(VideoPlayer.java:15)
Caused by: java.lang.ClassNotFoundException: org.slf4j.LoggerFactory
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 6 more
C:\Users\Alex\AppData\Local\NetBeans\Cache\8.1\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 0 seconds)
看起来vlcj正在努力工作,但我所做的只是换掉库文件夹中的.jar文件。有任何想法吗?