Jump to content
Sign in to follow this  

Get last played tracks in winamp

Recommended Posts


Is it possible to get that? From the player history in the media library?

Or from somewhere else? :P

Share this post

Link to post
Share on other sites

huh... I read the script you posted, but I can't get anything of that... you call some dlls, you do something with them ( don't know what ). And... then some while to get the whole name of the title... and read some bytes. I can't get it ;)

And the ActiveWinamp isn't a good choise, because If other users use the program and they don't have ActiveWinamp...

If it's hard to edit the script, forget about it... :P

Share this post

Link to post
Share on other sites

Here is a more polished version:

#Include <misc.au3>
#Include <array.au3>


Func PlaylistToArray()
    Local $songArray[1]    
    ;Retrieve Winamp window handle
    $winampHWND = WinGetHandle ( "[CLASS:Winamp v1.x]")

    If NOT $winampHWND Then
       MsgBox (0,"","Winamp does not appear to be running.")

    ;$PID = WinGetProcess($winampHWND)

    ;Return number of tracks in playlist
    $numTracks = _SendMessage($winampHWND, 0x0400, 0, 124, 0)
    If @error Then
       MsgBox (0,"","SendMessage failed." & @error)

    ;Return current playlist position (zero based)
    $currentTrack = _SendMessage($winampHWND, 0x0400, 0, 125, 0)
    If @error Then
       MsgBox (0,"","SendMessage failed." & @error)

    ;IMPORTANT - First song will be skipped without this
    $null = retrieveInfoByAddress(0, 0)

    For $X = 0 to $numTracks - 1
        $address = 0
        ;Return memory address of track title
        $address = _SendMessage($winampHWND, 0x0400, $X, 0xD4, 0)
        If @error Then SetError(1,1,1)    
        If $X > 0 Then
            Redim $songArray[$X + 1]
        $songArray[$X] = retrieveInfoByAddress($address, WinGetProcess($winampHWND))
    Return $SongArray

Func retrieveInfoByAddress($lpszTitle, $PID)

    ; Open the process so we can read from it. The call will return a process handle.
    $result = DllCall("kernel32.dll", "uint", "OpenProcess", "byte", 0x10, "int",0, "int", $PID)
    $ProcessHandle = $result[0]
    ; We have to read byte after byte until we encounter a "00" byte (string ends).
    $SongTitle = ""
    While 1

        ; Read from WinAMP's memory. Value will be copied into the string buffer, which must contain exactly one character because ReadProcessMemory won't terminate the string, only overwrite its contents.
        ;$Output = "x"  ; Put exactly one character in as a placeholder.
        Local $v_Struct = DllStructCreate ('byte[1]')
        DllCall('kernel32.dll', 'int', 'ReadProcessMemory', 'int', $ProcessHandle, 'int', $lpszTitle, 'int', DllStructGetPtr ($v_Struct, 1), 'int', 1, 'int', 0)   
        ; Error checking - i.e. no permission for reading from the process's memory
        If @error Then
            MsgBox (0,"","ReadProcessMemory failed: " & @error)
            DllCall("Kernel32.dll", "int", "CloseHandle", "int", $ProcessHandle)
            Return ""
        $temp = DllStructGetData ($v_Struct, 1)

        ; If the value of the byte read is zero we are at the end of the string.
        If $temp = 0 Then ExitLoop

        ; Append the character to our teststr variable that will hold the whole title string
        $SongTitle &= Chr($temp)

        ; Increment address by one to obtain next byte
        $lpszTitle += 1

    DllCall("Kernel32.dll", "int", "CloseHandle", "int", $ProcessHandle)  ; ErrorLevel and return value are not checked.
    Return $SongTitle

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.