向jpanel添加嵌入式媒体播放器组件时出错

pdtvr36n  于 2021-08-20  发布在  Java
关注(0)|答案(1)|浏览(410)

我尝试使用以下代码在simple 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)
eyh26e7m

eyh26e7m1#

在播放媒体之前,必须使相框可见。

相关问题