1

I am using the Xuggle library to play mp4 videos on a JPanel but video loading is taking 3 sec. or more. Do you have some advice how to play video on JPanel or JLabel in the right way?

Is this a good way to show mp4 video? VideoCodec is a Xuggle Codec. 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();
}
naugler
  • 1,060
  • 10
  • 31
Daniel Michalski
  • 545
  • 4
  • 14
  • 1
    What makes you think that a 3 sec load is slow? How big is the video? Anyway there are several proposes here http://stackoverflow.com/search?tab=relevance&q=play%20video%20swing – DSquare Nov 27 '13 at 18:57
  • This is a comercioanal app so it's sould be done in better way. 3 sec on my PC (win 8, core i7) but on the slower pc it's 5-6 sec. Video - mp4 (5-10MB). Maybe it's better way to show video. I'll find it. Thanks. – Daniel Michalski Nov 28 '13 at 07:10
  • I found solution. I used VLCJ library and now video is loading 1sec. Thanks :) – Daniel Michalski Nov 29 '13 at 22:38

1 Answers1

2

I found a solution. VLCJ library and 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();
}
Daniel Michalski
  • 545
  • 4
  • 14