我嘗試在畫布內放置VLCJ播放器。 我已經閱讀了很多關於它的主題,但我仍然無法實現我想要做的事情。在畫布中顯示VLCJ播放器
這裏是我使用的代碼:
public class RaspberryControler extends JFrame
{
/*Have to declare it in order to use vlcj*/
private EmbeddedMediaPlayerComponent mediaPlayerComponent;
private EmbeddedMediaPlayer mediaPlayer;
public RaspberryControler(String host){
this.host = host;
controler = new Controler(this);
initComponents();
}
private void initComponents(){
setBasicParameters();
createMainPanel();
createControlPanel();
createWebcamPanel();
mainPanel.add(webcamPanel);
mainPanel.add(controlPanel);
setListeners();
/*Set the last parameters of the frame*/
this.revalidate();
this.repaint();
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
}
private void createMainPanel(){
mainPanel = new JPanel();
/*Set the Layout*/
mainPanel.setLayout(new FlowLayout());
mainPanel.setVisible(true);
/*Set the parameters*/
this.getContentPane().add(mainPanel);
}
private void createWebcamPanel(){
/*Get the VLC Libraries*/
NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), "C:/VLC/VideoLAN/VLC");
Native.loadLibrary(RuntimeUtil.getLibVlcLibraryName(), LibVlc.class);
/*Create components*/
liveStream = new JLabel("Live Stream");
mediaPlayerComponent = new EmbeddedMediaPlayerComponent();
/*Set parameters of the components*/
liveStream.setPreferredSize(new Dimension(200, 30));
liveStream.setHorizontalAlignment(SwingConstants.CENTER);
/*Set the layout*/
webcamPanel = new JPanel();
webcamPanel.setLayout(new BorderLayout());
webcamPanel.setPreferredSize(new Dimension(550, 480));
webcamPanel.setBorder(BorderFactory.createLineBorder(Color.RED));
/*Place the components*/
webcamPanel.setVisible(true);
webcamPanel.add(liveStream, BorderLayout.NORTH);
webcamPanel.add(mediaPlayerComponent, BorderLayout.CENTER);
this.setVisible(true);
try{
mediaPlayerComponent.getMediaPlayer().playMedia("http://127.0.0.1:8989/movie");
}catch(IllegalStateException e){
System.out.println(e.toString());
}
}
然後,當然,WebcamPanel被添加到當前的JFrame。
我做錯了什麼?
這是輸出:The video surface component must be displayable
感謝那些會迴應!
PS:這裏是我籤的主題: - https://github.com/caprica/vlcj/issues/29 - Failed to play video by vlcj in java
謝謝你的回答!我更新了我的問題以更加準確,現在我使用EmbeddedMediaPlayer。不過,我有這個輸出:視頻表面組件必須是可顯示的。你知道這是什麼意思嗎? – Mornor 2014-10-28 15:34:09
謝謝你給我的幫助!我編輯了這個問題,以便代碼是我現在擁有的。我在嘗試播放流之前將幀設置爲可見,但我仍然有相同的錯誤。我不知道爲什麼...... – Mornor 2014-10-28 21:46:27
哦,是的,我的面板中確實有一個像我的面板的玩家(像黑色方塊),但錯誤當然還是存在。 – Mornor 2014-10-28 21:48:34