我面临以下异常
playing all sources
receiveed sources are : [wow24=/home/younes/Desktop/test.mp4, wow23=/home/younes/Desktop/test.mp4, wow26=/home/younes/Desktop/test.mp4, wow25=/home/younes/Desktop/test.mp4, wow28=/home/younes/Desktop/test.mp4, test=/home/younes/Desktop/test.mp4, wow1=/home/younes/Desktop/test.mp4, wow16=/home/younes/Desktop/test.mp4, wow27=/home/younes/Desktop/test.mp4, wow19=/home/younes/Desktop/test.mp4, wow18=/home/younes/Desktop/test.mp4, wow29=/home/younes/Desktop/test.mp4, wow9=/home/younes/Desktop/test.mp4, wow20=/home/younes/Desktop/test.mp4, wow31=/home/younes/Desktop/test.mp4, wow30=/home/younes/Desktop/test.mp4, wow22=/home/younes/Desktop/test.mp4, wow11=rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov, wow21=/home/younes/Desktop/test.mp4, wow10=rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov]
receiveed sources are : [wow24=/home/younes/Desktop/test.mp4, wow23=/home/younes/Desktop/test.mp4, wow26=/home/younes/Desktop/test.mp4, wow25=/home/younes/Desktop/test.mp4, wow28=/home/younes/Desktop/test.mp4, test=/home/younes/Desktop/test.mp4, wow1=/home/younes/Desktop/test.mp4, wow16=/home/younes/Desktop/test.mp4, wow27=/home/younes/Desktop/test.mp4, wow19=/home/younes/Desktop/test.mp4, wow18=/home/younes/Desktop/test.mp4, wow29=/home/younes/Desktop/test.mp4, wow9=/home/younes/Desktop/test.mp4, wow20=/home/younes/Desktop/test.mp4, wow31=/home/younes/Desktop/test.mp4, wow30=/home/younes/Desktop/test.mp4, wow22=/home/younes/Desktop/test.mp4, wow11=rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov, wow21=/home/younes/Desktop/test.mp4, wow10=rtsp://wowzaec2demo.streamlock.net/vod/mp4:BigBuckBunny_115k.mov]
adding panel wow24
adding panel wow24
playing all sources
Exception in thread "Thread-1" Exception in thread "Thread-2" java.util.NoSuchElementException
at sun.misc.CompoundEnumeration.nextElement(CompoundEnumeration.java:59)
at java.util.ServiceLoader$LazyIterator.hasNextService(ServiceLoader.java:357)
at java.util.ServiceLoader$LazyIterator.hasNext(ServiceLoader.java:393)
at java.util.ServiceLoader$1.hasNext(ServiceLoader.java:474)
at uk.co.caprica.vlcj.factory.discovery.provider.DirectoryProviderDiscoveryStrategy.getSupportedProviders(DirectoryProviderDiscoveryStrategy.java:75)
at uk.co.caprica.vlcj.factory.discovery.provider.DirectoryProviderDiscoveryStrategy.discoveryDirectories(DirectoryProviderDiscoveryStrategy.java:67)
at uk.co.caprica.vlcj.factory.discovery.strategy.BaseNativeDiscoveryStrategy.discover(BaseNativeDiscoveryStrategy.java:68)
at uk.co.caprica.vlcj.factory.discovery.NativeDiscovery.discover(NativeDiscovery.java:112)
at uk.co.caprica.vlcj.factory.MediaPlayerFactory.discoverNativeLibrary(MediaPlayerFactory.java:187)
at uk.co.caprica.vlcj.factory.MediaPlayerFactory.<init>(MediaPlayerFactory.java:119)
at uk.co.caprica.vlcj.factory.MediaPlayerFactory.<init>(MediaPlayerFactory.java:143)
at uk.co.caprica.vlcj.player.component.EmbeddedMediaPlayerComponent.initMediaPlayerFactory(EmbeddedMediaPlayerComponent.java:116)
at uk.co.caprica.vlcj.player.component.EmbeddedMediaPlayerComponent.<init>(EmbeddedMediaPlayerComponent.java:77)
at uk.co.caprica.vlcj.player.component.EmbeddedMediaPlayerComponent.<init>(EmbeddedMediaPlayerComponent.java:111)
at com.wanasis.vlc.view.VideoSlotPanel.<init>(VideoSlotPanel.java:101)
at com.wanasis.vlc.view.MainFrame.lambda$2(MainFrame.java:168)
at java.util.HashMap$EntrySet.forEach(HashMap.java:1044)
at com.wanasis.vlc.view.MainFrame.setupGridView(MainFrame.java:167)
at com.wanasis.vlc.view.MainFrame.lambda$0(MainFrame.java:84)
at java.lang.Thread.run(Thread.java:748)
at com.wanasis.vlc.view.MainFrame.setDisplayableSources(MainFrame.java:86)
at com.wanasis.vlc.control.MainFrameBuilder.lambda$1(MainFrameBuilder.java:98)
at java.lang.Thread.run(Thread.java:748)
java.util.NoSuchElementException
at sun.misc.CompoundEnumeration.nextElement(CompoundEnumeration.java:59)
at java.util.ServiceLoader$LazyIterator.hasNextService(ServiceLoader.java:357)
at java.util.ServiceLoader$LazyIterator.hasNext(ServiceLoader.java:393)
at java.util.ServiceLoader$1.hasNext(ServiceLoader.java:474)
at uk.co.caprica.vlcj.factory.discovery.provider.DirectoryProviderDiscoveryStrategy.getSupportedProviders(DirectoryProviderDiscoveryStrategy.java:75)
at uk.co.caprica.vlcj.factory.discovery.provider.DirectoryProviderDiscoveryStrategy.discoveryDirectories(DirectoryProviderDiscoveryStrategy.java:67)
at uk.co.caprica.vlcj.factory.discovery.strategy.BaseNativeDiscoveryStrategy.discover(BaseNativeDiscoveryStrategy.java:68)
at uk.co.caprica.vlcj.factory.discovery.NativeDiscovery.discover(NativeDiscovery.java:112)
at uk.co.caprica.vlcj.factory.MediaPlayerFactory.discoverNativeLibrary(MediaPlayerFactory.java:187)
at uk.co.caprica.vlcj.factory.MediaPlayerFactory.<init>(MediaPlayerFactory.java:119)
at uk.co.caprica.vlcj.factory.MediaPlayerFactory.<init>(MediaPlayerFactory.java:143)
at uk.co.caprica.vlcj.player.component.EmbeddedMediaPlayerComponent.initMediaPlayerFactory(EmbeddedMediaPlayerComponent.java:116)
at uk.co.caprica.vlcj.player.component.EmbeddedMediaPlayerComponent.<init>(EmbeddedMediaPlayerComponent.java:77)
at uk.co.caprica.vlcj.player.component.EmbeddedMediaPlayerComponent.<init>(EmbeddedMediaPlayerComponent.java:111)
at com.wanasis.vlc.view.VideoSlotPanel.<init>(VideoSlotPanel.java:101)
at com.wanasis.vlc.view.MainFrame.lambda$2(MainFrame.java:168)
at java.util.HashMap$EntrySet.forEach(HashMap.java:1044)
at com.wanasis.vlc.view.MainFrame.setupGridView(MainFrame.java:167)
at com.wanasis.vlc.view.MainFrame.lambda$0(MainFrame.java:84)
at java.lang.Thread.run(Thread.java:748)
at com.wanasis.vlc.view.MainFrame.setDisplayableSources(MainFrame.java:86)
at com.wanasis.vlc.control.MainFrameBuilder.lambda$1(MainFrameBuilder.java:98)
at java.lang.Thread.run(Thread.java:748)
the printed key is : wanaDVR
the printed key is : hjgfd
您可以猜到我正在同时播放多个视频,在这里实现这一点是我代码的所有重要部分
我有一个显示管理器,每次我的视频源更新时都会触发更新
public static void updateGridDisplay(HashMap<String, String> displayableSources) {
new Thread(() -> {
while (mainFrame == null || !mainFrame.isVisible())
try {
Thread.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
mainFrame.setDisplayableSources(displayableSources);
}).start();
}
设置可显示源的方法如下
public void setDisplayableSources(HashMap<String, String> displayableSources) {
this.displayableSources = new HashMap<>(displayableSources);
new Thread(() -> {
while (!isVisible()) {
try {
Thread.sleep(200);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
setupGridView();
}).run();
}
如您所见,我总是担心可见性,因为vlcj嵌入组件需要使组件可见才能正常工作
我的想法很简单:一个以面板为组成部分的网格,每个人都拿着它作为媒体播放器。
private void setupGridView() {
for (Component c : centerPanel.getComponents()) {
if (c instanceof VideoSlotPanel) {
VideoSlotPanel slotPanel = (VideoSlotPanel) c;
slotPanel.pause();
}
}
centerPanel.removeAll();
System.out.println("receiveed sources are : " + displayableSources.entrySet());
displayableSources.entrySet().forEach(entry -> {
centerPanel.add(new VideoSlotPanel(entry.getValue(), entry.getKey()));
});
centerPanel.revalidate();
revalidate();
centerPanel.repaint();
repaint();
if (isVisible())
for (Component c : centerPanel.getComponents()) {
if (c instanceof VideoSlotPanel) {
VideoSlotPanel slotPanel = (VideoSlotPanel) c;
slotPanel.play();
}
}
}
最后,视频广告位面板很简单,只需包装vlcj嵌入式视频组件
public VideoSlotPanel(final String source, final String title) {
this.title = title;
this.source = source;
System.out.println("adding panel "+title);
setLayout(new BorderLayout(0, 0));
setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
slotPanel = new JPanel();
add(slotPanel, BorderLayout.CENTER);
slotPanel.setLayout(new GridLayout(1, 0, 0, 0));
empc = new EmbeddedMediaPlayerComponent();
empc.mediaPlayer().input().enableKeyInputHandling(false);
empc.mediaPlayer().input().enableMouseInputHandling(false);
empc.videoSurfaceComponent().addMouseListener(new FullscreenShowMouseClickEvent());
slotPanel.add(empc);
SlotsManager.subscribe(this);
parent = this;
}
行代码empc = new EmbeddedMediaPlayerComponent();
引发了这种异常,为什么以及如何,我无法理解这一点,也无法通过逻辑推理加以解决,即使我采用线程化风格,我也认为这应该可行: JVM在开始运行应用程序之前具有所有必需的工具和类(重用vlcj API组件)
此错误每3或4次出现1次
普通应用中没有致命或破坏行为
我该怎么做