Results 1 to 22 of 22

Thread: VB6 - Get Winamp 5.xx currently playing module.

Threaded View

  1. #1

    Thread Starter
    Frenzied Member thegreatone's Avatar
    Join Date
    Aug 2003
    Location
    Oslo, Norway. Mhz:4800 x12
    Posts
    1,333

    VB6 - Get Winamp 5.xx currently playing module.

    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:
    1. 'In a module
    2. Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
    3. 'API call to get the windows text, this is useful as WinAMP's
    4. 'currently playing song is a part of its title.
    5. Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
    6. Public lHandle As Long
    7. 'this API call finds the WinAmp window when the correct parameters
    8. 'are passed to it.
    9.  
    10. Function getWinampWindow()
    11. 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
    12. If lHandle > 0 Then 'making sure the window exists
    13.     Dim lRet As Long
    14.     Dim sTitle As String * 256
    15.     Dim sCaption As String
    16.     lRet = GetWindowText(lHandle, sTitle, Len(sTitle))
    17.     sCaption = Left(sTitle, InStr(1, sTitle, vbNullChar, vbTextCompare) - 10)
    18.     Do
    19.         If IsNumeric(Left(sCaption, 1)) = True Or Left(sCaption, 1) = "." Or Left(sCaption, 1) = " " Then
    20.         sCaption = Right(sCaption, Len(sCaption) - 1)
    21.         Else
    22.         Exit Do
    23.         End If
    24.     Loop
    25.     Do
    26.         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.
    27.         sCaption = Left(sCaption, Len(sCaption) - 1)
    28.         ElseIf Right(sCaption, 1) = "(" Then
    29.         sCaption = Left(sCaption, Len(sCaption) - 1)
    30.         Exit Do
    31.         Else
    32.         Exit Do
    33.         End If
    34.     Loop
    35.     getWinampWindow = sCaption 'sets the return value of the module to the edited sCaption strong, which now contains the song name and artist...
    36. Else
    37.     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
    38. End If
    39. 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:
    1. 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:
    1. Private sub SongUpdate_Timer()
    2. SongUpdate.Enabled = False
    3. CurrentSong.Caption = getWinampWindow
    4. SongUpdate.Enabled = True
    5. 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.
    Attached Files Attached Files
    Last edited by thegreatone; May 3rd, 2005 at 09:52 AM.
    Zeegnahtuer?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width