caprica / vlcj

Java framework for the vlc media player
http://www.capricasoftware.co.uk/projects/vlcj
1.13k stars 259 forks source link

VLCJ 4.x ~ Video only plays 9 times on Raspberry Pi 4 #1221

Closed FolsomMike closed 5 months ago

FolsomMike commented 6 months ago

I am cleaning up the resources each time the video finishes, but it will only play 9 times on the Pi. Restarting the Java program solves the problem.

There does not seem to be a limit when running on Windows.

I have profiled my Java app and it is not losing heap space.

I have used htop on the Pi and cannot see any memory losses.

I read in the tutorial that there is no error logging by VLCJ 4.x. Is there any way to see what might be going on?

Should a new process appear in htop while the video is playing? I cannot find one popping up.

[Update]

When I switch to creating everything from a MediaPlayerFactory instead of using EmbeddedMediaPlayerComponent the problem goes away!

Is there some sort of artificial limit to the number of times a EmbeddedMediaPlayerComponent can be created on Linux?

    // Create a MediaPlayerFactory
MediaPlayerFactory mediaPlayerFactory = new MediaPlayerFactory();

// Create a JPanel to hold the video
this.setLayout(new BorderLayout());
//getContentPane().add(videoPanel, BorderLayout.CENTER);

// Create an EmbeddedMediaPlayer
mediaPlayer = mediaPlayerFactory.mediaPlayers().newEmbeddedMediaPlayer();
canvas = new Canvas();
mediaPlayer.videoSurface().set(mediaPlayerFactory.videoSurfaces().newVideoSurface(canvas));
this.add(canvas, BorderLayout.CENTER);

//clean up code executed when video complete:

if (mediaPlayer != null){ mediaPlayer.release(); }
caprica commented 6 months ago

No, there is no such limit.

But, you are really supposed to re-use your existing media player rather than create one and release one each time you play media.

I suspect, after your updated comment, that maybe one of the Java objects is being garbage collected. Because vlcj uses native code, you have to make sure you keep hard references to your vlcj Java objects.

No, a new process should not appear just because you play a video, it should all be part of the JVM process.

If you post a self-contained test case with your EmbeddedMediaPlayer implementation that might help.

FolsomMike commented 6 months ago

I have taken care to prevent my objects from being Garbage Collected (the ones I have control of), and I am forcing Garbage Collection between plays to make sure nothing is accumulating.

I have going to update Java on the Pi to see if it solves another issue...the overlay window is not transparent...I will see if that affects the 9 play limit as well.