Sign in to follow this  
Followers 0
Didonet

Get last played tracks in winamp

5 posts in this topic

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

#4 ·  Posted (edited)

Don't ask me why this works. It looks like it shouldn't but it does.

There is a great SendMessage reference for Winamp here:

http://forums.winamp.com/showthread.php?threadid=180297

CODE REMOVED - SEE NEXT POST

Edited by weaponx

Share this post


Link to post
Share on other sites

Here is a more polished version:

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

_ArrayDisplay(PlaylistToArray())

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.")
       Exit
    EndIf

    ;$PID = WinGetProcess($winampHWND)

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

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

    ;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]
        EndIf
        
        $songArray[$X] = retrieveInfoByAddress($address, WinGetProcess($winampHWND))
    Next
    
    Return $SongArray
EndFunc

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 ""
        EndIf
       
        $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
    WEnd

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

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  
Followers 0