VB.Net - Getting Current WMP Song Title

I want to create a simple VB.Net program that gets the name of the current song playing on windows media player. For example, I will have a textbox and a button. When the button is clicked the song artist and title will be displayed in the textbox. I really don’t think this is that complicated but I could be wrong. I am running WMP 9 with the blogger plug-in installed if that matters. Is there a way to use that in VB or even a way to just grab the title bar information? Thanks in advance!

PS. If you need any clarifications just let me know.

Ironically, I just did something like this using Winamp.

And, for the life of me, I can’t figure out how to port it to WMP. Winamp was easier because the song currently playing is scrolled in the titlebar.

Yeah, thats what I’ve heard. The thing is with the blogger plug-in the name of the artist and song are put into the title bar for just that reason. I’m not sure if its just looks or if it really is part of the title bar or not. Seems to me the plug-in would put it up there and there would be an easy way, similar to winamp, to extract it.

I am still a big fan of winamp caphis and would be happy to hear how you accomplished the same task.

Oh, well, if it’s in the title bar, then this will work. You will have to truncate the return value however WMP formats (ie: “Windows Media Player - song - title” or whatever), but that should be easy.



Private Declare Auto Function FindWindow Lib "user32" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr
Private Declare Auto Function GetWindowText Lib "user32" (ByVal hwnd As IntPtr, ByVal lpString As String, ByVal cch As Integer) As Integer

Private Function GetWMPTitleBar() As String
     Dim hwnd As IntPtr = FindWindow("WMPlayerApp", vbNullString)
     Dim lpText As New String(Chr(0), 100)
     Dim intLength As Integer = GetWindowText(hwnd, lpText, lpText.Length)
     Dim strTitle As String = lpText.Substring(0, intLength)
     If (strTitle = vbNullString) Then
          Return "nothing playing"
     Else
          Return strTitle
     End If
End Function