2

When playing a long video using vlcj's EmbeddedMediaPlayer instance, the computer enters a locked or (depending on my configuration) sleep mode while the video is playing. Unlocking or waking up the computer often causes failures in the playback.

The easiest and most obvious way to handle this is to turn off sleep and/or locking on your computer. If, however, you need your computer to lock or sleep only when not playing a video, this is not the best solution. The best solution is to somehow disable sleeping or locking while the video is playing.

The VLC player does this without problems. I have played 2+ hour videos using it on different operating systems without my system sleeping or locking. I know that this is possible, but I cannot find any information on doing this using VLCJ.

Is there a call or series of calls that I can make that will prevent a machine from sleeping or locking while a video is being played? If so, how do I engage this functionality?

Factor Three
  • 2,094
  • 5
  • 35
  • 51
  • 1
    I'm not sure about _preventing_ the computer from going to sleep or locking, but there is the [SystemSleepListener](https://docs.oracle.com/en/java/javase/18/docs/api/java.desktop/java/awt/desktop/SystemSleepListener.html) and [UserSessionListener](https://docs.oracle.com/en/java/javase/18/docs/api/java.desktop/java/awt/desktop/UserSessionListener.html) interfaces as part of the `java.awt.Desktop` API. Maybe you could do some cleanup or other preventative measures to avoid the playback failures. Note you may have to execute some code on the EDT instead of the FX thread, not sure. – Slaw Aug 25 '22 at 19:07
  • vlcj isn not really responsible here. What vlcj is doing is embedding VLC via LibVLC and video playback and its interaction with the operating system is entirely delegated to VLC. On Linux, I remember writing some native code to interact with DBus to prevent screensaver and powersave from occuring when my video was playing. On Windows, I don't know. – caprica Aug 26 '22 at 06:08
  • Caprica: how does the VLC player prevent sleeping/locking on a Windows machine? Is there some native code that it uses? If so, perhaps a JNI function can be created for use from VLCJ (or JavaFX)... – Factor Three Aug 26 '22 at 13:05
  • I don't know how VLC does it. I thought there was an OS setting that controlled this, in the power management profile somewhere, but this doesn't explain the difference between VLC and your LibVLC/vlcj application. I don't really routinely use Windows unless I have to, so I can't suggest anything else. – caprica Aug 26 '22 at 13:50
  • In VLC sources, look for "inhibit", you can also try "--disable-screensaver" as a media player factory argument, and hope that this also prevents power management. – caprica Aug 26 '22 at 13:52
  • I looked into this on a Windows 10 laptop, fully upgraded. Ordinarily the laptop would sleep after 10 minutes, yet my vlcj application runs for significantly longer than that and does not enter sleep mode. – caprica Aug 28 '22 at 11:39

0 Answers0