Я пытаюсь поместить игрока 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
Благодарю вас за помощь, которую вы мне дадите! Я отредактировал вопрос, чтобы код был тем, что у меня есть сейчас. Перед тем как попытаться воспроизвести поток, я установил рамку, но у меня все еще есть такая же ошибка. Я не знаю, почему ... – Mornor
О да, и у меня действительно что-то похожее на игрока в моей панели (например, на черный квадрат), но ошибка, конечно же, все еще есть. – Mornor