I want to create a C++ application that can detect what song is currently playing on Spotify. I noticed that Windows displays the track information in those media control popups when you adjust volume or pause music using function keys. Since Spotify doesn’t offer a public API for this kind of integration, I’m wondering if there’s a way to access this media information that Windows already captures. Has anyone successfully retrieved the current playing track data from Spotify through Windows system calls or other methods in C++? Any suggestions on which Windows APIs or libraries might help with this would be great.
you could also try windows media foundation apis - the mfmediaengine stuff works well. it’s more complex than smtc but you get way more control over media sessions. some people hook into notifications too since spotify pushes track changes there. just heads up - it’s not 100% reliable and the metadata sometimes caches weird.
You could also try the SetWinEventHook API to catch accessibility events from Spotify’s window. When tracks change, Spotify updates its window title and UI elements, which fires accessibility notifications. I’ve had good luck monitoring EVENT_OBJECT_NAMECHANGE events that target Spotify’s process specifically. It’s lighter than the Windows Runtime approach since you’re just listening for window changes instead of dealing with media session APIs. The main downside? It’s less standardized - you’ll have to parse whatever window title format Spotify uses, and they could change it anytime. But it’s surprisingly reliable for basic track detection and doesn’t need the newer Windows Runtime stuff if you’re working with older systems.
try systemmediatransportcontrols - ive used it and it works pretty well with spotify. you can grab title and artist info without needing their api. just look into windows runtime apis, theyre accessible through c++ with the winrt headers.
Windows Media Session API (SMTC) is definitely the way to go. I built something similar last year - querying GlobalSystemMediaTransportControlsSessionManager works great for grabbing current track metadata from Spotify. You’ll need Windows Runtime C++ projections and link against windowsapp.lib. The tricky bit is handling async API calls properly. Make sure your event handlers are set up right to catch media property changes. One gotcha: Spotify doesn’t always populate all metadata fields, so add null checks for artist and album info. Bonus - this works with most media players, not just Spotify, so your app becomes way more versatile.
I ran into this same issue a few months ago. Ended up using the Windows Media Control API through COM interfaces - specifically hooking into ISystemMediaTransportControls via Windows Runtime. Set up a session watcher that monitors media property changes in real-time. You’ll need Windows Runtime headers and Windows 10+ since older versions don’t handle this properly. The Windows Runtime activation factories are pretty verbose in C++, but once you get past the boilerplate, pulling metadata is easy. Heads up though - Spotify’s sometimes slow to update the system with new track info, especially if you’re skipping songs fast.
This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.