PDA

View Full Version : Get Current Song Playing in Windows Media Player


google eyes
07-01-2006, 04:00 PM
How would I go about getting the current song playing with Windows Media Player, or even Winamp. Right now, I'm doing it a very messy way, and this way only works with Winamp.

To get the current song playing for Winamp, I just get Winamp's tittle, and it gives me the current song.

Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long


Private Sub Form_Load()
Dim hwnd As Long
Dim GetTitle As Long
Dim Title As String

Title = Space$(255)

hwnd = FindWindow("winamp v1.x", vbNullString) 'find the winamp window

If hwnd > 0 Then 'if we find the winamp window
GetTile = GetWindowText(hwnd, Title, 255) 'Get the title of the winamp window and put it in "Title"
MsgBox Title
End If

End Sub

There HAS to be a more efficient way, hasn't there? Plus, I know they're a way to get the current song playing in Windows Media Player. Any suggestions?

Thank you.

Cert
07-01-2006, 06:33 PM
No, that is about the only way to do it. That essentially is how the Winamp API does it. There are Winamp API calls for track length, position, etc, but not for the title. But how is that not efficient? lol It's pretty straight forward.

As far as WMP is concerned, there was a plugin available from Microsoft I believe (for which version or all versions I don't know) that would write the currently playing song to the registry and then you could retrieve that information from the registry for your program. I don't know if the newer versions of WMP have any window captions or such that you can grab like for Winamp. You'll probably need some type of WMP plugin regardless.

angelofwisdom
07-02-2006, 10:46 AM
Not very helpful, I guess, but MSN Messenger retrieves the WMP current song; and with an external plugin, it can retrieve Winamp's too.
If I were you I'd search a little more about how to use that plugin. However, I'm not sure if it comes with WMP or if MSN Messenger installs it.......

Regards
angelofwisdom

RealityRipple
07-03-2006, 12:47 AM
There is a Blogging Plugin for Windows Media Player. It comes with some "Fun Pack" or other for wmp9. I use it for a program I've made, and you can get the installer for it here: http://rcb.realityripple.com/WMPblog.zip
When you have run the installer, open WMP. Go to tools>Plugins>Options. Select Background. If Blogging is not listed, hit Add. Navigate to C:\Program Files\Windows Media Player\Plugins\WMPBLOG, and select blogging.dll. Hit open. If it is listed, or when this is done, Check Blogging Plugin and hit OK. this will put the current song title into the Windows Media Player Window Title. it can then be extracted in similar fashion to Winamp.

Also, the code you have is the best way to do it.