English 中文(简体)
试图在JPanel的WindowsCanvas中将vlcj媒体插手
原标题:Trying to embed vlcj media player in a WindowsCanvas inside a JPanel

我试图在JPanel内部播放使用vlcj的录像,但我没有工作。 我获得的信息例外是“java.lang.IllegalStateException: 视频表面成分必须显示”,这与

The Code of the JPanel which includes the canvas and the vlcj role is this:

import javax.swing.JPanel;

import com.sun.jna.Native;
import com.sun.jna.NativeLibrary;

import java.awt.Canvas;
import java.awt.Color;

import uk.co.caprica.vlcj.binding.LibVlc;
import uk.co.caprica.vlcj.player.MediaPlayerFactory;
import uk.co.caprica.vlcj.player.embedded.EmbeddedMediaPlayer;
import uk.co.caprica.vlcj.player.embedded.videosurface.CanvasVideoSurface;
import uk.co.caprica.vlcj.runtime.RuntimeUtil;
import uk.co.caprica.vlcj.runtime.windows.WindowsCanvas;

public class MyJPanel extends JPanel {
private EmbeddedMediaPlayer player;
private WindowsCanvas canvas;

public MyJPanel() {
    canvas = new WindowsCanvas();
    add(canvas);
    revalidate();
    repaint();

    canvas.setVisible(true);

    MediaPlayerFactory mediaPlayerFactory = new MediaPlayerFactory();
    player = mediaPlayerFactory.newEmbeddedMediaPlayer();

    CanvasVideoSurface videoSurface = mediaPlayerFactory.newVideoSurface(canvas);

    player.setVideoSurface(videoSurface);
    player.playMedia("v.avi");   // This sentence throws the exception.
}
}

MyJFrame 扩展了JFrame,只包括MyJPanel JPanel。 我认为这根本不重要。

import javax.swing.JFrame;

public class MyJFrame extends JFrame {
protected MyJPanel myJPanel;

public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                MyJFrame frame = new MyJFrame();
                frame.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

public MyJFrame() {
    myJPanel = new myJPanel();
    add(myJPanel);
}   
}

提前感谢。

最佳回答

你在发现含有信道的画面之前,试图发挥媒体的作用。 您需要将<条码>Media()以单独的方法发出,并将其称作<>>>>整个框架已经建立并明确。

EDIT:

如果你仍然想直截了当,就在你创建并显示你的框架之后,就把相关方法称为:

MyJFrame frame = new MyJFrame();
frame.setVisible(true);
frame.startPlaying();

...obviously you ll need to define startPlaying() on MyJFrame, but then it should start playing straight off. you just need to set the frame visible first.

问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...