检查是否在Windows 10上使用Python播放音频 [英] Check if audio playing with Python on Windows 10
问题描述
我正在Windows 10上使用Python 3.7.我想检测计算机上是否有音频播放.我一直在寻找 win32api.GetVolumeinformation
,但无法获得想要的东西.
I'm working with Python 3.7 on Windows 10.
I would like to detect if there is any audio playing on my computer or not.
I was looking into win32api.GetVolumeinformation
but I'm unable to get what I want.
控制音频时,您可以查看是否正在播放一个程序,我想实现这一目标.
When you control your audio you can see if there is a program playing and I want to achieve that.
推荐答案
使用winrt尝试以下api:枚举选项在此处列出,但您可以使用 mediaIs("PAUSED")
, mediaIs("PLAYING")
等...
Try this api using winrt:
The enum options are listed here, but you can use mediaIs("PAUSED")
, mediaIs("PLAYING")
ect...
import asyncio, winrt.windows.media.control as wmc
def mediaIs(state):
session = asyncio.run(getMediaSession())
if session == None:
return False
return int(wmc.GlobalSystemMediaTransportControlsSessionPlaybackStatus[state]) == session.get_playback_info().playback_status #get media state enum and compare to current main media session state
也有很多更有用的winrt API来控制Windows上的媒体
There are heaps more useful winrt APIs to control media on windows too here.
这篇关于检查是否在Windows 10上使用Python播放音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!