79567457

Date: 2025-04-10 19:46:56
Score: 0.5
Natty:
Report link

After some time experimenting I've discovered a way to do this. Python's winrt binding library exposes the GlobalSystemMediaTransportControlsSessionManager, after getting the current session you can call get_timeline_properties(), which in turn will give you a GlobalSystemMediaTransportControlsSessionTimelineProperties object, that exposes a couple of useful attributes, including the current position of a playing track. Some credit goes to this question.

So, assuming current_session from the linked question, a simple one-liner to get the position is:
current_session.get_timeline_properties().position.seconds

Note: It seems it likes to lag for about 2 seconds behind the actual track, and there's no finer resolution, only full seconds are supported it seems.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Enderek