I'm using VLCJ for playing mp4 video in my swing application. It can play properly but when I pause() the video followed by a play() it cannot display video but it is able to resume audio. If I call stop() instead of pause() everything works fine but it starts playing from the beginning. How can I pause the video properly so that I can resume the video?
I was trying with the following class:
public class JVLCPlayerPanel extends javax.swing.JPanel
{
private File vlcPath = new File("C:\\Program Files\\VideoLAN\\VLC");
private EmbeddedMediaPlayer player;
public JVLCPlayerPanel() {
initComponents();
NativeLibrary.addSearchPath("libvlc", vlcPath.getAbsolutePath());
EmbeddedMediaPlayerComponent videoCanvas = new EmbeddedMediaPlayerComponent();
this.setLayout(new BorderLayout());
this.add(videoCanvas, BorderLayout.CENTER);
this.player = videoCanvas.getMediaPlayer();
this.player.setPause(true);
}
public void play(String media)
{
player.prepareMedia(media);
player.parseMedia();
player.play();
}
public void pause()
{
player.pause();
}
public void resume()
{
player.play();
}
}
According to your post and comments, you are trying to switch a single media player component between multiple panels.
This simply does not work.
With vlcj/LibVLC the component that hosts the video surface must be "displayable" and must remain so at all times. You can not "re-parent" the video surface to another component, you can not even hide the component (you can set it to 1x1, or the best solution is to use a CardLayout, to hide it).
The reason it works when you first stop then play is that in this case vlcj will "re-associate" the video surface with the native media player. This can not be done while the video is playing. There's nothing you can do about it.
Probably keeping one media player per panel, and using a CardLayout, is the best solution.