[英]How to play mp4 video on JPanel?
I am using the Xuggle library to play mp4 videos on a JPanel but video loading is taking 3 sec. 我正在使用Xuggle库在JPanel上播放mp4视频,但是视频加载需要3秒钟。 or more. 或者更多。 Do you have some advice how to play video on JPanel or JLabel in the right way? 您对如何以正确的方式在JPanel或JLabel上播放视频有一些建议吗?
Is this a good way to show mp4 video? 这是显示mp4视频的好方法吗? VideoCodec is a Xuggle Codec. VideoCodec是Xuggle编解码器。 This is working but I have a delay of a few seconds. 这正在工作,但我有几秒钟的延迟。
public void setVideoName(final String videoName) {
imageAndVideoPanel.removeAll();
final VideoPanel videoPanel = new VideoPanel();
videoPanel.setPreferredSize(Const.Dimensions.VIDEO_SIZE);
videoPanel.setMinimumSize(Const.Dimensions.VIDEO_SIZE);
videoPanel.setMaximumSize(Const.Dimensions.VIDEO_SIZE);
imageAndVideoPanel.add(videoPanel);
new Thread(new Runnable() {
@Override
public void run() {
VideoCodec videoCodec =
new VideoCodec(videoPanel, videoName + TextsDao.getText("videoFilesExtension"));
}
}).start();
}
I found a solution. 我找到了解决方案。 VLCJ library and EmbeddedMediaPlayer. VLCJ库和EmbeddedMediaPlayer。 Code to play video/ image is simple: 播放视频/图像的代码很简单:
public class ExamQuestionsLeftPanel extends JPanel {
private EmbeddedMediaPlayerComponent component;
private EmbeddedMediaPlayer player;
... ...
public ExamQuestionsLeftPanel() {
setUpPanel();
initializeComponents();
}
private void setUpPanel() {
NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(), "VLCx86");
component = new EmbeddedMediaPlayerComponent();
player = component.getMediaPlayer();
Border emptyBorder = BorderFactory.createEmptyBorder(10, 10, 10, 10);
setLayout(null);
setBackground(Const.Colors.EXAM_BACKGROUND_COLOR);
setAlignmentX(Component.LEFT_ALIGNMENT);
setBorder(emptyBorder);
}
... ...
public void setImageName(String imageName) {
player.stop();
player.prepareMedia("media" + File.separator + imageName);
player.parseMedia();
player.play();
}
public void setVideoName(final String videoTitle) {
new Thread(new Runnable() {
@Override
public void run() {
player.stop();
player.prepareMedia("media" + File.separator + videoTitle);
player.parseMedia();
player.play();
}
}).start();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.