PDA

Click to See Complete Forum and Search --> : [VB6]: Extracting current WMP song


Paul M
Feb 12th, 2007, 04:14 AM
This just basically tell you if WMP is loaded then if it is playing a song and if it is what song. This might not work with some WMP versions i haven't tested with 11.0 but it might.

Option Explicit
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long


Public Function strGetText(lngHwnd As Long) As String
Dim ilngLength As Long
Dim strBuffer As String

ilngLength = SendMessageLong(lngHwnd, &HE, 0, 0)
strBuffer = String$(ilngLength, 0)
SendMessageByString lngHwnd, &HD, ilngLength + 1, strBuffer
strGetText = strBuffer
Exit Function

Resume Next
End Function


Public Function getWMPT() As String
Dim stringtxt As String
Dim wmplng As Long

wmplng = FindWindow("WMPlayerAPP", vbNullString)

If wmplng = 0 Then
getWMPT = "WMP is not loaded currently"
Else
stringtxt = strGetText(wmplng)

If stringtxt = "Windows Media Player" Then
getWMPT = "No Song is currently being played"
Else
stringtxt = wmplng
getWMPT = Trim$(Left$(stringtxt, InStr(1, stringtxt, " - Windows Media Player")))

End If
End If

Exit Function
Resume Next

End Function

TheBigB
Feb 27th, 2007, 08:22 AM
I guess it works, but not for 11.0 at least not the song info. It can detect activity for WMP, but not the song.

Paul M
Mar 24th, 2007, 07:11 AM
It should almost detect the window for any version of windows media player but yes extracting the song title is a problem :(

kingzl3y
Jun 21st, 2007, 04:17 AM
Urgh, I have a problem with this code.
I'm not really sure where to put it :\
Anychance you've got an example project for me darling?
Thanx

Paul M
Jun 23rd, 2007, 03:26 AM
I wouldn't worry for about it to much it only calls the song in older versions :( But in any case that would do in a module :)

But i am working on getting the song title in newer versions of WMP for my new project. Winamp support and itunes support is complete. But WMP is a little trickier though i got it working in C++ just need to convert it and tidy it up a little ;) then i will release the source :D

kingzl3y
Jul 26th, 2007, 03:14 PM
Hey!
Sorry i haven't replied or anything.
I haven't even touched VB in about 9 weeks, it isn't good :(
I've decided to spend more time on it..get some more apps up and running and whatever ^^
anyway
Back to this, i wacked the code in a module created some txtboxes and told the tb's to read the variables.
AND i get this:
http://i18.tinypic.com/67eyb94.jpg

this is my code
Module
Option Explicit
Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function SendMessageByString Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As String) As Long
Public Function strGetText(lngHwnd As Long) As String
Dim ilngLength As Long
Dim strBuffer As String
ilngLength = SendMessageLong(lngHwnd, &HE, 0, 0)
strBuffer = String$(ilngLength, 0)
SendMessageByString lngHwnd, &HD, ilngLength + 1, strBuffer
strGetText = strBuffer
Exit Function
Resume Next
End Function
Public Function getWMPT() As String
Dim stringtxt As String
Dim wmplng As Long
wmplng = FindWindow("WMPlayerAPP", vbNullString)
If wmplng = 0 Then
getWMPT = "WMP is not loaded currently"
Else
stringtxt = strGetText(wmplng)
If stringtxt = "Windows Media Player" Then
getWMPT = "No Song is currently being played"
Else
stringtxt = wmplng
getWMPT = Trim$(Left$(stringtxt, InStr(1, stringtxt, " - Windows Media Player")))
End If
End If
Exit Function
Resume Next
End Function



and this in my Form1

Private Sub Command1_Click()
Text1.Text = getWMPT
Text2.Text = stringtxt
End Sub

Its probably all wrong, i haven't touched VB for ages..and i wasn't that good at it anyway..so
Don't laugh
^^


THANKS!

TheBigB
Sep 19th, 2007, 11:13 AM
there is no problem with your app, wmp just doesn't allow this anymore (from WMP11) without your app being a plug-in.

i think i'm going to take a try at developing such a thing.