I'm currently working on my first project in Python. My main problem is getting a function to run in parallel without stopping the rest of the program.
import asyncio
from winsdk.windows.media.control import GlobalSystemMediaTransportControlsSessionManager as MediaManager
async def init():
manager = await MediaManager.request_async()
global media_changed_token
media_changed_token = manager.get_current_session().add_media_properties_changed(handle_media_changed)
asyncio.create_task(media_changed())
event = asyncio.Event()
await event.wait()```
This `init()` function is run once as part of the entire program. The goal is to run the `handle_media_changed` function every time the media Windows is currently playing changes (using `winsdk`, which seems pretty undocumented).
This works, except the `await event.wait()` stops the rest of the program from running, as there are things that should happen after the `init` function in the main loop, but removing the `await`ing prevents the `handle_media_changed` function from firing at all.
My basic understanding of asyncio doesn't really allow me to find the "right" way/alternative to do this. Any help is appreciated. ๐