将嵌入式媒体播放器组件添加到 JPanel 时出错
Error while adding embedded media Player component to JPanel
我尝试使用此代码在简单的 jframe 上显示视频:
package com.company;
import javax.swing.*;
import java.awt.*;
import uk.co.caprica.vlcj.player.component.EmbeddedMediaPlayerComponent;
public class Main {
static EmbeddedMediaPlayerComponent myMedia = new EmbeddedMediaPlayerComponent();
public static void main(String[] args) {
JFrame j = new JFrame("Stream player");
JPanel jp = new JPanel();
jp.setBounds(0, 0, 700, 300);
jp.setLayout(null);
myMedia.mediaPlayer().media().start("C:\Users\cikko\Downloads\Video\144.mp4");
myMedia.setBounds(0, 0, 700, 280);
jp.setBackground(Color.BLACK);
jp.add(myMedia);
j.add(jp);
j.setSize(700, 300);
j.setLayout(null);
j.setVisible(true);
}
}
但它给出了错误。我尝试更改 jpanel 布局,但它也没有用。如何解决?谢谢
Exception in thread "main" java.lang.IllegalStateException: The video surface component must be displayable
at uk.co.caprica.vlcj.player.embedded.videosurface.ComponentVideoSurface.attach(ComponentVideoSurface.java:66)
在播放媒体之前,您必须使框架可见。
我尝试使用此代码在简单的 jframe 上显示视频:
package com.company;
import javax.swing.*;
import java.awt.*;
import uk.co.caprica.vlcj.player.component.EmbeddedMediaPlayerComponent;
public class Main {
static EmbeddedMediaPlayerComponent myMedia = new EmbeddedMediaPlayerComponent();
public static void main(String[] args) {
JFrame j = new JFrame("Stream player");
JPanel jp = new JPanel();
jp.setBounds(0, 0, 700, 300);
jp.setLayout(null);
myMedia.mediaPlayer().media().start("C:\Users\cikko\Downloads\Video\144.mp4");
myMedia.setBounds(0, 0, 700, 280);
jp.setBackground(Color.BLACK);
jp.add(myMedia);
j.add(jp);
j.setSize(700, 300);
j.setLayout(null);
j.setVisible(true);
}
}
但它给出了错误。我尝试更改 jpanel 布局,但它也没有用。如何解决?谢谢
Exception in thread "main" java.lang.IllegalStateException: The video surface component must be displayable
at uk.co.caprica.vlcj.player.embedded.videosurface.ComponentVideoSurface.attach(ComponentVideoSurface.java:66)
在播放媒体之前,您必须使框架可见。