我试图在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);
}
}
提前感谢。