1

I would like to know how to detect if current windows is playing any kind of media (video, music, etc) similar to what energy settings do to decide if the computer can enter sleep/hibernate mode?

I'm trying to detect how long the computer is idle. I'm currently using the GetLastInputInfo from user32.dll but it just take in consideration the user input, but not if there is any media playing which should not consider the computer idle.

I tried to find C# APIs or native invocations but can't find the information. I'm using latest version of .NET Framework.

Alexandre Leites
  • 388
  • 1
  • 4
  • 15

1 Answers1

1

Generally speaking, programs don't declare that they are playing media - instead they call SetThreadExecutionState to tell Windows that the computer should not sleep.

That said - Windows 10 recently added support for programs to declare to the OS that they are currently playing media so that they're integrated with Windows' media controls (like how on iOS any program playing video or audio can be controlled from the Control Center).

Here's what appears on my screen when I nudge my volume control:

enter image description here

...however Chrome is being buggy here because I'm not actually playing any media in Chrome but it's telling Windows that it is.

I don't know what Windows API is used to set this - or which API is used to check it - but it isn't very widely used - even Windows' built-in Windows Media Player 12 doesn't use it.

Dai
  • 141,631
  • 28
  • 261
  • 374
  • That's just Chrome reacting to physical media keyboard buttons (or in my case [mapped ones](https://github.com/stuartd/keymapper)). I finally got fed up with it today, and got rid of it using a Chrome flag - https://www.tenforums.com/tutorials/134484-enable-disable-chrome-exe-volume-control-media-key-handling.html – stuartd Jul 31 '19 at 00:47
  • @stuartd Other applications respond to global-hotkey registrations of MediaKeys and they don't cause Windows' built-in media controls to appear. – Dai Jul 31 '19 at 01:14
  • @stuartd That is Windows 10's built-in media controls. It says "chrome.exe" because Chrome has (incorrectly) told Windows that is is playing media and that Windows should send any media-control messages to Chrome. Edge browser does it too, see here: https://www.onmsft.com/news/latest-microsoft-edge-insider-builds-now-show-media-info-in-windows-10-volume-overlay – Dai Aug 01 '19 at 00:42
  • ah thanks and sorry , I've just never seen it before. Disabling the `hardware-media-key-handling` flag made it go away anyway. I literally only use Chrome for stuff on my work accounts and never media, so I really don't know what it was up to. – stuartd Aug 01 '19 at 09:48