I am using vlcj
to play video in a Java Swing application. I want to be able to switch from one VideoSurface
to another during playback. This is working fine if I first stop the vlcj
mediaPlayer
, assign a new VideoSurface
to it and then restart the player again. The thing is, I want the switch to work seamlessly. If I skip the stop/restart part, I am seeing a grey screen with no video being displayed in the newly assigned VideoSurface
. According to the documentation, setting a new surface should be possible. Am I missing something?
final Canvas canvas1 = new Canvas();
final Canvas canvas2 = new Canvas();
ComponentVideoSurface videoSurface = null;
videoSurface = factory.newVideoSurface(canvas1);
mediaPlayer.videoSurface().set(videoSurface);
// start playback...
videoSurface = factory.newVideoSurface(canvas2);
mediaPlayer.videoSurface().set(videoSurface);
There is no video output on surface2
. If I switch back to surface1
, I can see it.
Thanks in advance!
Edit:
I also tried removing the first canvas from its Container
and adding the same reference to another one (so, I did not set a new VideoSurface
, I just moved the existing one into another Container
), but the effect was the same.
The answer is simply that you can not switch video surface while playing media.
(Well, I suppose you can switch it, but it won't take effect.)
You can not "re-parent" the video surface to a different container either, so for example it won't work in a docking window framework without stopping and restarting video.
My usual recommendation for something like this is instead to write a custom LayoutManager that can shift your various components around without changing the actual video surface associated to the media player.