Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Playing videos still prevents the system from entering sleep mode or activating the screensaver #4957

Open
Taiizor opened this issue Nov 29, 2024 Discussed in #4956 · 0 comments

Comments

@Taiizor
Copy link

Taiizor commented Nov 29, 2024

Discussed in #4956

Originally posted by Taiizor November 29, 2024
Hello,

I am using WebView2 in my WPF project to play a looping video. However, as long as the window remains open, neither the screensaver activates nor does the system go to sleep.

Below is a code snippet I tried as a solution, but it didn't resolve the issue:

[DllImport("user32.dll", SetLastError = true)]
private static extern void SetThreadExecutionState(uint esFlags);

private const uint ES_CONTINUOUS = 0x80000000;
private const uint ES_SYSTEM_REQUIRED = 0x00000001;
private const uint ES_DISPLAY_REQUIRED = 0x00000002;

private void AllowScreenSaver()
{
    SetThreadExecutionState(ES_CONTINUOUS);
}

private void PreventScreenSaver()
{
    SetThreadExecutionState(ES_CONTINUOUS | ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED);
}

Additionally, I tried using launcher arguments like --disable-background-timer-throttling --disable-renderer-backgrounding --disable-backgrounding-occluded-windows, but these didn’t work either.

Interestingly, the issue is resolved in MpvPlayer by setting the stop-screensaver option to no. When reviewing its code, I noticed that it uses ES_CONTINUOUS.

https://github.com/mpv-player/mpv/blob/a283f66ede58e0182ac8cd4c930238144427fa74/video/out/w32_common.c#L2326

case VOCTRL_KILL_SCREENSAVER:
	w32->disable_screensaver = true;
	SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED);
	return VO_TRUE;
case VOCTRL_RESTORE_SCREENSAVER:
	w32->disable_screensaver = false;
	SetThreadExecutionState(ES_CONTINUOUS);
	return VO_TRUE;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant