检查是否在Windows 10上使用Python播放音频 [英] Check if audio playing with Python on Windows 10

查看:152
本文介绍了检查是否在Windows 10上使用Python播放音频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆