An Application of mine retrieves the current playing song from a multitude of music players. However, I'm having great trouble implementing Zune and Windows Media Player.
I've done a lot of googling on the subject, unfortunately it's only confusing me more and more.
What I would normally do for my other applications:
- Iterate over all open windows every 4 seconds
- Get the title of all windows
- Check title for a pattern (Ie,
" - Spotify "
) - If it's there, adjust the title for output.
WMP Does not have the current playing song in the title.
Zune does, but it's rotating every few seconds between title, album and artist. Which is heavily unreliable to track with my current method, albeit possible.
Windows Media Player
I've also tried using the COM component for windows media player.
import win32com.client
wmp = win32com.client.gencache.EnsureDispatch('WMPlayer.OCX')
# some function I don't have here, it retrieves the current playing song
# and other data
The big problem with that it requires you to start WMP programmatically, which would be extremely user unfriendly
So, what have I found? This SO post redirects to WMP.dll. But as far as I've read, it has the same problem as the COM, you have to start it programmatically. If not, I would really like some directions on how to work with that dll in python.
There would be another a little less hacky solution, which is to write a plugin for WMP, let my users download that plugin and retrieve the data from that plugin. I'd rather not go there, since I have no experience with any of the C languages, nor do I feel like digging into plugin documentations for this.
Zune
A method would be to cycle through the three title states, determine which state it's currently at and find the position of the other two.
IE: First 5 seconds the title is: Super_song Next 5 seconds the title is: By Power_artist Next 5 seconds the title is: Good_album (date)
So I could determine when the album title is by making a regex for the date (which is always there) and then find the title and artist by waiting a few seconds.
This is obviously not a great solution, since it'll take a while and it's not very reliable either, (what if the song name contains a date for example)
The next problem is that it's not consistent either, sometimes the title just stays Zune for minutes long. No idea why.
So, move on to the next method.
There's this application called ZuneNowPlaying. This "somehow" gets the current playing song from Zune and puts it in the registry, this thing does not work with my sloppy title method, since it changes the registry the instant the song changes. Immediately.
This is the solution I had used in the working version of my program, but many users reported that it simply didn't work, nothing happened. And I checked the program and it doesn't reliably change the registry all the time. I don't know why, I don't know how to fix it. Therefor, this solution is also -scrapped-.
Is the fact that it is using the name "MsnMsgrUIManager"#000000"> causing the zune software to send it information about which song is playing? Is there a way to get this information without this kind of hack?
That is found in the discussion of the Zune Now Playing application. The source is not available unfortunately, at least I can't find it. Anyone got more on this?
Third method I had heard of was once again, a dll. ZuneShell.dll it's called. I don't remember where I read about it, nor can I find it via google, since all results are "Is ZuneShell.dll a virus?".
Once again, I run into the problem that I wouldn't know how to work with this even IF I had documentation on it, heck, if it's even what I have been looking for.
Alternate directions to maybe look into
While browsing about this subject, I've seen people talking about retrieving data directly from GUI's. I'm not sure how legit, possible or even how correct my memory of it is, but if it's possible could someone redirect me to more on this?
Anything else, really.