Search code examples
javamedia-playervlcj

Error while adding embedded media Player component to JPanel


I tried this code to display a video on 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);
    }

}

but it gives error. I tried change jpanel layout but it didn't work either. How To Can I solve it? Thanks

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)



Solution

  • You must make your frame visible before you play your media.