Reputation: 43
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.
Upvotes: 2
Views: 3584
Reputation: 147
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
async def getMediaSession():
sessions = await wmc.GlobalSystemMediaTransportControlsSessionManager.request_async()
session = sessions.get_current_session()
return session
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
There are heaps more useful winrt APIs to control media on windows too here.
Upvotes: 2