VLC playback and energy configuration

Microsoft Windows specific usage questions
Forum rules
Please post only Windows specific questions in this forum category. If you don't know where to post, please read the different forums' rules. Thanks.
ygoe
Blank Cone
Blank Cone
Posts: 19
Joined: 26 Nov 2011 11:59

VLC playback and energy configuration

Postby ygoe » 06 May 2019 21:58

A friend has asked me: When I play back audio on my Surface Pro, it stops after a few songs. This is the energy configuration which puts the device in sleep mode after a few minutes on battery. We don't want to change that, but he does want the music to keep on playing, which is totally understandable. I would want the same.

So I've been reading a bit about that. Keeping the device active is only possible with video, not audio, but it wouldn't apply anyway because it also keeps the screen on which isn't needed for audio and only drains the battery faster. Windows' presentation mode does the same, and it complicated to toggle. (He's not very computer-experienced and needs very simple solutions.)

I thought it would be a good solution to change Windows energy settings while VLC is playing audio. It can be done with a simple call to powercfg.exe. I'm already using that for other purposes through the Windows task scheduler. But How do I know when VLC is playing audio? Good ol' WinAmp could be queried by WM messages and the SendMessage function. Does something similar exist for VLC?

Then I found that VLC can host extensions of some sort. I never used this but would it be possible to install an extension that would call powercfg.exe for me when audio playback starts or stops? Where should I start reading about how to use that?

Are there any other ideas about this kind of VLC automation? How do you handle this issue?

Wait, now that I've searched again, I believe VLC could also handle this itself properly. Do the VLC developers know the [url=https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-setthreadexecutionstate]SetThreadExecutionState[/url] function? It doesn't just allow the process to keep the display on (which I thought), it can also prevent standby but allow display idle. That sounds like the proper solution to the requirement. But it would either need to be integrated into VLC, or be used through some other VLC API means, as asked above.

ygoe
Blank Cone
Blank Cone
Posts: 19
Joined: 26 Nov 2011 11:59

Re: VLC playback and energy configuration

Postby ygoe » 09 May 2019 18:46

So the SetThreadExecutionState function is only used in modules\video_output\win32\inhibit.c and it is always used in a way that prevents the display to turn off, never the system alone. Looks like this isn't all that could be done with it. It only covers video playback but totally ignores audio playback. It feels like VLC only cares about the video it plays but isn't interested in the audio. Is this a bug? Or an enhancement request?

If the VLC developers are not interested in reliable audio playback with this application, can somebody please give me some advice how I can fix this with a plugin for VLC or a third-party tool? In any case I'd need to know when VLC is playing audio and when not. With this event I could handle the rest to make it work.

unidan
Developer
Developer
Posts: 1493
Joined: 25 Mar 2018 01:00

Re: VLC playback and energy configuration

Postby unidan » 10 May 2019 17:41

Hi,

As you found out, the modules related to power saving features are inhibitors. But since VLC 3, inhibitors are only triggered by the video output, not the audio output, as it leads to different issues like screen burning or minor physical security issue.
I would be interested in fixing this issue but I currently don't know if Windows allows to configure the power saving features to be able to lock but avoid sleeping. If your hint works, why not.

To be able to know if VLC is playing, you could
+ use the windows sound API
+ parse VLC logs
+ use dbus on linux or implement another RPC in VLC
+ use remote interface like HTTP or rc
+ write an interface module, but it's much harder than the others

I don't often use Windows so I won't be able to advise you any third party tools.

ygoe
Blank Cone
Blank Cone
Posts: 19
Joined: 26 Nov 2011 11:59

Re: VLC playback and energy configuration

Postby ygoe » 10 May 2019 18:16

I think I can find out whether the Windows API function has the desired effect. I'll create a test application (outside VLC) to see what happens.

ygoe
Blank Cone
Blank Cone
Posts: 19
Joined: 26 Nov 2011 11:59

Re: VLC playback and energy configuration

Postby ygoe » 10 May 2019 20:38

Yep, that works as expected. Requiring the display will keep it on. Requiring just the system will allow the display to turn off and the computer to lock but keep the system active. VLC audio playback then continues while the monitor is off and the device needs minimal power. No other code required, just this one function call.

That'd be great if it could be built into VLC.

unidan
Developer
Developer
Posts: 1493
Joined: 25 Mar 2018 01:00

Re: VLC playback and energy configuration

Postby unidan » 15 May 2019 18:50

Thank you for looking into this, it's on my todolist now. ;)

ygoe
Blank Cone
Blank Cone
Posts: 19
Joined: 26 Nov 2011 11:59

Re: VLC playback and energy configuration

Postby ygoe » 07 Jun 2020 17:30

Just a short follow-up, could you already make any progress with this?


Return to “VLC media player for Windows Troubleshooting”

Who is online

Users browsing this forum: No registered users and 60 guests