我試圖播放視頻使用vlcj內JPanel,但它不適合我。我得到的消息異常是「java.lang.IllegalStateException:視頻表面組件必須可顯示」,這與Keep getting an Error "Component must be displayable"中的問題相同。試圖嵌入vlcj媒體播放器在一個WindowsCanvas內JPanel
其中包含畫布和vlcj球員的JPanel的代碼是這樣的:
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);
}
}
在此先感謝。
我可以問十幾個問題,但他們都將在1 [SSCCE](http://sscce.org/)中回答。爲什麼不發佈SSCCE? –
@AndrewThompson編輯。謝謝。 – honnix
O ... K這兩個來源中的哪一個是SSCCE? –