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.
Re: VB6 - Get Winamp 5.xx currently playing module.
I mentioned being able to create a decent logfile of your played songs... i gave Pseudo Code, now, i bring to you, and example using the very same module as before
Here is the code for the main Form, i will comment it and show you what is going on :
VB Code:
Dim CurrSong As String 'this is where the current song will be stored, it will be used in comparisons later on, and so is important.
Private Sub Command1_Click()
If Command1.Caption = "Start Logging Songs" Then 'checks to see the caption of the command button
Timer1.Enabled = True 'enables the simple timer that will be used to log songs
Else:
Timer1.Enabled = False 'turns the timer off
Command1.Caption = "Start Logging Songs" 'changes the command buttons caption
End If
End Sub
Private Sub Command2_Click()
On Error GoTo SAVE_ERROR 'error trapping
Dim intX As Integer
CD.Filter = "Text File (*.txt)|*.txt" 'set the output of the common dialog control to text files
CD.ShowSave 'shows the common dialogs save menu
Open CD.FileName For Output As #2
For intX = 0 To List1.ListCount - 1 'loops through the listbox adding all the items to file
Print #2, List1.List(intX)
Next
Close #2
Exit Sub
SAVE_ERROR:
MsgBox Err.Num & " " & Err.Description, vbOKOnly, "" 'tells the end user what the error was
End Sub
Private Sub Command3_Click()
List1.Clear 'clears the log of songs
End Sub
Private Sub Form_Load()
Call Update 'Calling the update function straight away ensures the program id up-to-date with the currently playing song.
End Sub
Function Update()
Label1.Caption = getWinampWindow 'calls the module to gain the currently playing songs title
End Function
Private Sub Timer1_Timer()
Timer1.Enabled = False 'turns the timer off, just incase processing this Sub takes longer than expected.
Label1.Caption = getWinampWindow 'updates the Label to display the currently playing song.
CurrSong = getWinampWindow 'updates the currently playing song string via the module
If Left(CurrSong, 9) = "[Opening]" Then CurrSong = Right(CurrSong, Len(CurrSong) - 10) 'strips the [opening] tag that may exist on the song if Winamp is struggling to open a particular file
If List1.ListCount > 0 Then List1.ListIndex = 0
If CurrSong = List1.Text Then 'if the same song is still playing as the last update then skip anything from now, and do not re-add the song to the log
Else:
List1.AddItem CurrSong, 0 'adds the currently playing song to the top of the list
End If
Timer1.Enabled = True 'turns the timer back on, so the process can be repeated again.
End Sub
The module mentioned is unchanged from the one posted above.
Enjoy the use of this example
Edit: Compiled .Exe removed from attachment - Hack
Sorry, i didn't notice that until last night when it was too late, BUT, the Winamp 5.xx Series is called Winamp 6 amongst many people i know, because they reason the Winamp original was actually Winamp 0.
I will change the title
And the code, but i shall leave the download how it is
Re: VB6 - Get Winamp 5.xx currently playing module.
Here are some changes i'v donne to the module to try to fix a problem that i had with winamp modern skin, addeded id3v2 support to it and mpeg info reading too...
'Updated by [url=http://www.vbforums.com/member.php?u=44830]Thegreatone[/url]
'
'Re-Update by ME :=)
'(problem opening id3 editor solved, working for
'winamp modern skin, addeded id3v2 tag reading support)
'improvement of ID3v1 and ID3v2 reading/checking
'addeded MPEG info reading, fixed getWinampWindowText bug
'
'Feel free to mail comments, bugs, advice
'I'd appreciate it if you gave me some credit
'If you make a program out of this. If not
'then it's ok, but I wouldn't mind seeing the
'program, so feel free to send me programs you
'make with this.
Originally Posted by thegreatone
Used like so -
VB Code:
FindWinamp
getWinampWindowText
GetMp3Info
MsgBox MP3Info.id3v2_Album
MsgBox MP3Info.id3v2_Artist
MsgBox MP3Info.id3v2_Comment
MsgBox MP3Info.id3v2_Composer
MsgBox MP3Info.id3v2_Copyright
MsgBox MP3Info.id3v2_EncodedBy
MsgBox MP3Info.id3v2_Genre
MsgBox MP3Info.id3v2_OrgArtist
MsgBox MP3Info.id3v2_Title
MsgBox MP3Info.id3v2_Track
MsgBox MP3Info.id3v2_Url
MsgBox MP3Info.id3v2_Year
There you go
Edit1: ID3v2 state checking (addeded)
Edit2: Addeded MPEG info support (addeded)
Edit3: ID3v1 state checking (addeded)
Edit4: Fixed a little problem in getWinampWindowText:
Re: VB6 - Get Winamp 5.xx currently playing module.
hehe true indeed, i might change that module soon...i wanted to add a mpeg info reading too but unfortunatly won't be this weekend.
I'm trying to find out all the conts used in winamp to some things can be speeded up a bit.
Re: VB6 - Get Winamp 5.xx currently playing module.
Originally Posted by TDQWERTY
hehe true indeed, i might change that module soon...i wanted to add a mpeg info reading too but unfortunatly won't be this weekend.
I'm trying to find out all the conts used in winamp to some things can be speeded up a bit.
That could get tricky very fast.
I thik there is a way of making Winamp update your program automagically, i'm looking into it soon.
Re: VB6 - Get Winamp 5.xx currently playing module.
Great job Thegreatone & TDQWERTY. I have just begun to play with VB. Would you by chance have the same type of thing for Musicmatch? Specifically, I am looking for a way to access the ID3V2 tag info in Musicmatch. Any help is appreciated.
Re: VB6 - Get Winamp 5.xx currently playing module.
codebank isn't the right place to ask this type of thinks.
but no, i'v never try that program.
I have try this with winamp due to some fun controling 2 media boxes over the internet to my house...
as far as i remember musicmatch was too heavy for this kind of things, although it migh be donne. It's all a mather of shorcuts and handles.
Re: VB6 - Get Winamp 5.xx currently playing module.
Originally Posted by L-B-P-O
Great job Thegreatone & TDQWERTY. I have just begun to play with VB. Would you by chance have the same type of thing for Musicmatch? Specifically, I am looking for a way to access the ID3V2 tag info in Musicmatch. Any help is appreciated.
Same here i'm afraid never used the program.
However, the code used could also be re-used in a few ways to work with Musicmatch. I'm guessing with some work using Spy++ you could retrieve the information needed as we did.
Re: VB6 - Get Winamp 5.xx currently playing module.
Ok, so i threw it through the converter and ended up with a workingversion, it has one bug i know of so far, that when winamp first loads it simply shows "wi" until you play a song.
It's attached, but i'm unsure whether this is worthy of the codebank for .Net submisions.
Re: VB6 - Get Winamp 5.xx currently playing module.
Originally Posted by thegreatone
I mentioned being able to create a decent logfile of your played songs... i gave Pseudo Code, now, i bring to you, and example using the very same module as before
Here is the code for the main Form, i will comment it and show you what is going on :
VB Code:
Dim CurrSong As String 'this is where the current song will be stored, it will be used in comparisons later on, and so is important.
Private Sub Command1_Click()
If Command1.Caption = "Start Logging Songs" Then 'checks to see the caption of the command button
Timer1.Enabled = True 'enables the simple timer that will be used to log songs
Else:
Timer1.Enabled = False 'turns the timer off
Command1.Caption = "Start Logging Songs" 'changes the command buttons caption
End If
End Sub
Private Sub Command2_Click()
On Error GoTo SAVE_ERROR 'error trapping
Dim intX As Integer
CD.Filter = "Text File (*.txt)|*.txt" 'set the output of the common dialog control to text files
CD.ShowSave 'shows the common dialogs save menu
Open CD.FileName For Output As #2
For intX = 0 To List1.ListCount - 1 'loops through the listbox adding all the items to file
Print #2, List1.List(intX)
Next
Close #2
Exit Sub
SAVE_ERROR:
MsgBox Err.Num & " " & Err.Description, vbOKOnly, "" 'tells the end user what the error was
End Sub
Private Sub Command3_Click()
List1.Clear 'clears the log of songs
End Sub
Private Sub Form_Load()
Call Update 'Calling the update function straight away ensures the program id up-to-date with the currently playing song.
End Sub
Function Update()
Label1.Caption = getWinampWindow 'calls the module to gain the currently playing songs title
End Function
Private Sub Timer1_Timer()
Timer1.Enabled = False 'turns the timer off, just incase processing this Sub takes longer than expected.
Label1.Caption = getWinampWindow 'updates the Label to display the currently playing song.
CurrSong = getWinampWindow 'updates the currently playing song string via the module
If Left(CurrSong, 9) = "[Opening]" Then CurrSong = Right(CurrSong, Len(CurrSong) - 10) 'strips the [opening] tag that may exist on the song if Winamp is struggling to open a particular file
If List1.ListCount > 0 Then List1.ListIndex = 0
If CurrSong = List1.Text Then 'if the same song is still playing as the last update then skip anything from now, and do not re-add the song to the log
Else:
List1.AddItem CurrSong, 0 'adds the currently playing song to the top of the list
End If
Timer1.Enabled = True 'turns the timer back on, so the process can be repeated again.
End Sub
The module mentioned is unchanged from the one posted above.
Enjoy the use of this example
Edit: Compiled .Exe removed from attachment - Hack
I like this solution, but i need date and time when song is played.
I believe that can be done with date and time stamp. As well, song duration would be interesting to add.
So, can anyone help me how to add time stamp in this project ?
Any kind of help would be good for me !
Sorry, i didn't notice that until last night when it was too late, BUT, the Winamp 5.xx Series is called Winamp 6 amongst many people i know, because they reason the Winamp original was actually Winamp 0.
I will change the title
And the code, but i shall leave the download how it is
Did you find this code useful ?
Actually, there was no version "0". The real reason for the jump from 3 to 5 (ignoring 4) is hilarious.
From the Winamp FAQ:
You're not imagining things. Yes, we skipped a version number for the following reasons: a) Winamp 5 combines the best aspects of Winamp 2 and Winamp 3 into one player. Hence Winamp 2 + Winamp 3 = Winamp 5! b) Who the hell wants to see a Winamp 4 Skin :P c) We think that a Fibonacci sequence for versioning might be pretty damn cool. d)We improved so much in Winamp 5 that we figured it warranted skipping a version.