[英]How to detect media playing with C#?
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.
我当前正在使用来自user32.dll的GetLastInputInfo,但它只是考虑了用户输入,但是如果有正在播放的媒体不应该考虑计算机空闲,则不会考虑。
I tried to find C# APIs or native invocations but can't find the information. 我试图找到C#API或本机调用,但是找不到信息。 I'm using latest version of .NET Framework.
我正在使用最新版本的.NET Framework。
Generally speaking, programs don't declare that they are playing media - instead they call SetThreadExecutionState
to tell Windows that the computer should not sleep. 一般来说,程序不会声明它们正在播放媒体-而是调用
SetThreadExecutionState
来告知Windows计算机不应该休眠。
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). 就是说-Windows 10最近增加了对程序的支持,以向OS声明它们当前正在播放媒体,以便它们与Windows的媒体控件集成在一起(例如,如何在iOS上通过“控制中心”控制播放视频或音频的任何程序) )。
Here's what appears on my screen when I nudge my volume control: 当我轻按音量控制时,屏幕上会显示以下内容:
...however Chrome is being buggy here because I'm not actually playing any media in Chrome but it's telling Windows that it is. ...但是Chrome在这里存在问题,因为我实际上并没有在Chrome中播放任何媒体,而是告诉Windows确实如此。
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. 我不知道使用什么Windows API来设置此功能-或使用哪个API来检查它-但使用范围不是很广泛-即使Windows内置的Windows Media Player 12也没有使用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.