WinAMP

Online Playlist for Winamp

Maybe you've noticed, or maybe not. But the Home page, contains a little Playlist, this list contains the last 10 music files played by me ... quiet neat eh?
The idea was inspired on an existing Playlist Service for Winamp, but rather using the existing service, I thought it would be cooler if I was able to write it myself ... and so I began the challenge ...

Step 1: Programming language

I've choosen for Visual Basic 6 because it's fairly easy to create a Winamp plugin in VB6 thanks to GenWrapper, and I don't know C++ enough to create an plugin.

Step 2: Get the current song

This is pretty easy ... WinAMP places the current playing song in it's titlebar ... Win32API allows us to grab text from any window we want, if we know the Handle of that particular window. We can use the FindWindow API or even better, GenWrapper has a function to get the Handle, so why not use this function?
Plugin.cls
...
Private Sub IRjlWinAmpGenPlugin_Initialize(ByVal Wrapper As RjlWinAmpGenLib.IRjlWinAmpGenWrapper)
   Set moGenWrapper = Wrapper
   moGenWrapper.Description = "Kedero.com - Online Playlist for Winamp"

   ModMain.miWinamp = oGenWrapper.HwndParent
...
So, we can detect the current playing song ... but every 3-4 minutes the songs changes and there's no song_changed event or something like that. But we can use a timer function to detect every 10, 20, 30, ... seconds if the song has changed.
...
   miTimer = SetTimer(&H0, &H0, 10000, AddressOf TimerProc)
End Sub
We know the handle of the WinAMP window and we have a timer ... next thing we need is ofcourse the function to grab the song from WinAMP. Like I told you before, we can grab the text of any window we want. This can be accomplished through the GetWindowText API.
ModMain.bas
...
Public Function GetSong() As String
   Dim sHwndText As String * 256
   GetWindowText miWinamp, sHwndText, 256

   Dim sSong As String
   sSong = Trim(sHwndText)

   GetSong = sSong
End Function
...

Step 3: Posting the data (client)

The next step is posting the data to the website ... ofcourse we only post to the site if Winamp is playing another song and if winamp is playing ...
...
Public Sub TimerProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal idEvent As Long, ByVal dwTimer As Long)
...
   Dim oRequest As WinHttp.WinHttpRequest
   Set oRequest = New WinHttp.WinHttpRequest
   oRequest.Open "POST", "htto://kedero.com/some_page.aspx"
   oRequest.SetRequestHeader "Music", msMusic
   oRequest.Send ""
   End If
...
End Sub
...

Step 4: Save the data (server)

This step is fairly easy, to fetch the data, you only need one line of code
Some_Page.aspx.vb
...
Dim sMusic As String = Request.Headers("Music")
...
To save the data you need a database, or you can save to an xml file ...

Other fancy stuff

Depending on the way you store the songs in the database, you can fetch populair songs, last played songs, favorite artist, ... As you can see, it's fairly easy to code ... and it's quite fun to place on your site ...