简体   繁体   English

如何检测使用C#播放的媒体?

[英]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.

相关问题 从网络播放媒体播放器C# - Media player c# playing from network 我怎么知道visual c#中的Windows Media Player控件何时播放完一首歌? - How can I know when a Windows Media Player control in visual c# has finished of playing a song? 多个URL播放C#Windows Media Player - Multiple URL playing C# Windows Media Player 从Windows Media Player(C#)检索当前正在播放的歌曲 - Retrieving currently playing song from Windows Media Player (C#) c#在Windows媒体播放器中播放电影“不”嵌入 - c# playing movie in windows media player “Not” embedded 从C#在Windows Media Player上播放的视频中获取图像 - Take image from video playing on windows media player in C# C#全屏播放嵌入式Windows Media Player - C# playing embedded Windows Media Player in fullscreen 如何在C#应用程序中没有IMAPI的情况下检测CD / DVD驱动器中的媒体类型? - How to detect media type in a CD/DVD drive without IMAPI in a C# application? Visual Studio 22 WPF C# MediaElement - 没有媒体显示,但在 Designer 中媒体继续播放 - Visual Studio 22 WPF C# MediaElement - No Media is showing up but in Designer the media keeps playing 如何知道音频在C#中播放是否完成? - How to know if audio is done playing c#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM