问题描述
FXMLController初始化方法:
FXMLController initialize method:
@FXML
private VBox vbContainer;
MediaPlayerVLC m_mediaPlayer;
public void initialize(URL url, ResourceBundle rb) {
final SwingNode swingNode = new SwingNode();
m_mediaPlayer = new MediaPlayerVLC();
createAndSetSwingContent(swingNode, m_mediaPlayer);
vbContainer.getChildren().add(0, swingNode);
}
和createAndSetSwingContent():
And createAndSetSwingContent():
private void createAndSetSwingContent(final SwingNode swingNode, JComponent jComponent) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
swingNode.setContent(jComponent);
}
});
}
MediaPlayerVLC类:
MediaPlayerVLC class:
package javafxswing;
import javax.swing.JPanel;
import uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent;
public class MediaPlayerVLC extends JPanel {
private final EmbeddedMediaPlayerComponent mediaPlayerComponent;
public MediaPlayerVLC() {
setSize(350, 320);
setVisible(true);
mediaPlayerComponent = new EmbeddedMediaPlayerComponent();
mediaPlayerComponent.setSize(350, 320);
add(mediaPlayerComponent);
}
public MediaPlayer getMediaPlayer() {
return mediaPlayerComponent.getMediaPlayer();
}
}
我点击一个按钮播放媒体FXMLController:
And I play the media by clicking a button, in FXMLController:
@FXML
private void handleButtonAction(ActionEvent event) {
System.out.println("You clicked me!");
m_currentVideo = "video.mov";
m_mediaPlayer.getMediaPlayer().playMedia(m_currentVideo);
}
现在,问题是:视频开始播放但我看不到图像。我说它开始播放因为我能听到音频。我做错了什么?
Now, the problem: The video starts to play but I can see no image. I say it starts to play because I can hear the audio. What am I doing wrong?
任何帮助高度赞赏。
推荐答案
简而言之,它不会以这种方式工作。
In short, it won't work this way.
来自Javdoc的 SwingNode
这里:
From the Javdoc for SwingNode
here: http://docs.oracle.com/javase/8/javafx/api/javafx/embed/swing/SwingNode.html
它表示部分:
在vlcj的情况下, EmbeddedMediaPlayerComponent
扩展 Panel
,一个重量级的AWT组件。
In the case of vlcj, the EmbeddedMediaPlayerComponent
extends Panel
, a heavyweight AWT component.
要与vlcj一起使用JavaFX,您可能需要自己直接渲染视频数据。这就是vlcj所谓的 DirectMediaPlayerComponent
的用途。这种方法的本质是 DirectMediaPlayerComponent
接收要渲染的每帧视频数据,然后你自己使用 PixelWriter $渲染它c $ c>或你提出的其他一些方法。
To use with vlcj with JavaFX you will likely have to render the video data directly yourself. This is what vlcj's so-called DirectMediaPlayerComponent
is for. The essence of this approach is that the DirectMediaPlayerComponent
receives each frame of video data to render, and you would then render this yourself using a PixelWriter
or some other means that you come up with.
这里有一个vlcj-javafx项目,这种方法适用于Java7。由于错误的线程,它不能与Java8一起使用,在此处记录:
There is a vlcj-javafx project here https://github.com/caprica/vlcj-javafx, and this approach works up to Java7. It does not work with Java8 due to wrong threading, documented here: https://github.com/caprica/vlcj-javafx/issues/3
这篇关于使用SwingNode在JavaFX中显示VlcJ的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!