Hi, in this thread i will show you how to get the currently playing winamp 5.xx series song, the original code was found by me, unworking, and abandoned, i have fixed this and made this work once again.
Enjoy.
VB Code:
'In a module
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
'API call to get the windows text, this is useful as WinAMP's
'currently playing song is a part of its title.
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public lHandle As Long
'this API call finds the WinAmp window when the correct parameters
'are passed to it.
Function getWinampWindow()
lHandle = FindWindow("Winamp v1.x", vbNullString) 'This is for finding the window, "Winamp v1.x" is the reference to the window type of the Winamp pogram
If lHandle > 0 Then 'making sure the window exists
If IsNumeric(Left(sCaption, 1)) = True Or Left(sCaption, 1) = "." Or Left(sCaption, 1) = " " Then
sCaption = Right(sCaption, Len(sCaption) - 1)
Else
Exit Do
End If
Loop
Do
If IsNumeric(Right(sCaption, 1)) = True Or Right(sCaption, 1) = ")" Or Right(sCaption, 1) = " " Or Right(sCaption, 1) = ":" Then 'removes the number from the winamp currently playing song.
sCaption = Left(sCaption, Len(sCaption) - 1)
ElseIf Right(sCaption, 1) = "(" Then
sCaption = Left(sCaption, Len(sCaption) - 1)
Exit Do
Else
Exit Do
End If
Loop
getWinampWindow = sCaption 'sets the return value of the module to the edited sCaption strong, which now contains the song name and artist...
Else
getWinampWindow = "Winamp 5 Series Not Found" 'sets the return value of the module to the edited sCaption string which has jut been set because the winamp title could not be found
End If
End Function
Usage:
Using this module is simple, no need to declare anything in your forms, no need to register anything, simply call "getWinampWindow" as if it was a string, for example :
VB Code:
msgbox getWinampWindow
It could even be used in a timer to periodically update a Label to show the currently playing song. For example - (where SongUpdate is a timer, CurrentSong is a label)
VB Code:
Private sub SongUpdate_Timer()
SongUpdate.Enabled = False
CurrentSong.Caption = getWinampWindow
SongUpdate.Enabled = True
End Sub
Experimenting with this you could record you very own music played log, although you would need to compare the two Listbox entries to make sure no songs appear more than once in a row, especially if used in a timer, you could make it only add the song if the song before it was different.
Some pseudo-code for this would be -
-----------------------------------------
Get the last song (listindex = 0) and save it to a string
Compare this string to getWinampWindow
Add getWinampWindow if the two aren't equal
Don;t add it if they are equal
-----------------------------------------
Enjoy
I will attach a sample project as well.
Last edited by thegreatone; May 3rd, 2005 at 09:52 AM.