Sign in to follow this  
Followers 0
oapjr

[Help] How to get the path of the music being played on WMP or VLC?

11 posts in this topic

Hi,

I'd like to create a hotkey to delete the music that is being played on WMP or VLC and then play the next music of the playlist.

Can someone help me?

Thanks

Share this post


Link to post
Share on other sites



oapjr,

Sure, I'll give it a go! ;)

Anonymous

1 person likes this

Spoiler

censored.jpg

 

Share this post


Link to post
Share on other sites

It depends on what you mean by "delete the music and then play the next music of the playlist". Delete it from where, the playlist or the disk?


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

It depends on what you mean by "delete the music and then play the next music of the playlist". Delete it from where, the playlist or the disk?

 

Delete from disk.

The script should be something like this:

; Hotkey
HotKeySet ('^t', "Delete")

Func Delete()
    ; something here to get the path of the music being played

    ; play the next music on the playlist
    Send("{MEDIA_NEXT}")

    ; delete the music
    FileRecycle("path")
EndFunc

I don't know how to get the path of the music.

Edited by oapjr

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

oapjr,

I haven't forgot about ya. :)

Give this a try. Note its for testing purposes only, meaning it dosen't delete anything although you could simply add the command to do so if it works. The file has to be playing...du

#NoTrayIcon
#include "WinAPIEx.au3"
#include "APIConstants.au3"
#include <WinAPI.au3>

; Note that the functions below were thrown together and need heavy optimization!
#include <Array.au3> ; For example only
#include <File.au3>

Dim $aFiles = _ProcessListFiles("wmplayer.exe") ; Get a list of files currently opened by the process

$aFiles = _ArrayUnique($aFiles) ; Remove duplicate entries

Dim $bAllFilesExist = False
Do ; Loop through the array and remove invalid entries
    $bAllFilesExist = True
    For $i = 1 To UBound($aFiles, 1) - 1 Step 1
        If Not FileExists($aFiles[$i]) Then
            _ArrayDelete($aFiles, $i) ; Files dosen't exist so remove it from the array
            $bAllFilesExist = False
            $aFiles[0] -= 1
            ExitLoop
        EndIf
    Next
Until $bAllFilesExist

MsgBox(262144, "FileDelete", _GetAudioFileFromArray($aFiles))  ; Display the result

_ArrayDisplay($aFiles) ; Display the result
Exit

Func _GetAudioFileFromArray(ByRef $aFiles)
    Local $aPath, $szDrive, $szDir, $szFName, $szExt
    For $i = 1 To $aFiles[0] Step 1
        $aPath = _PathSplit($aFiles[$i], $szDrive, $szDir, $szFName, $szExt)
        If StringRegExp($aPath[4], "(mp3|wav|ogg|wma)") Then
            Return $aFiles[$i]
        EndIf
    Next
EndFunc

Func _ProcessListFiles($vProcess)
    _AdjustPrivilege(20)
    ; Retrieve PID from process name
    Local $nProcessId = ProcessExists($vProcess)
    ; Create structure to store public object type information
    Local $tPOTI = DllStructCreate('ushort;ushort;ptr;byte[128]'), $aRet
    ; Get the full list of open handles via PID
    Local $aHandles = _WinAPI_EnumProcessHandles($nProcessId)
    ; Variable declaration and open target process for handle duplication
    Local $hObject, $hProcess = _WinAPI_OpenProcess($PROCESS_DUP_HANDLE, 0, $nProcessId, True), $pData, $Length, $tString, $nFiles = 0
    ; Iterate through each handle listed and duplicate into our own process for object information gathering
    For $i = 1 To $aHandles[0][0] Step 1
        ; Prevent Hangup on certain access rights!
        If $aHandles[$i][3] == 0x00120189 Then
            $aHandles[$i][0] = 0
            ContinueLoop
        EndIf
        If $aHandles[$i][3] == 0x0012019f Then
            $aHandles[$i][0] = 0
            ContinueLoop
        EndIf
        If $aHandles[$i][3] == 0x00100000 Then
            $aHandles[$i][0] = 0
            ContinueLoop
        EndIf
        ; Duplicate handle is neccessary to retrieve object information
        $hObject = _WinAPI_DuplicateHandle($hProcess, $aHandles[$i][0], _WinAPI_GetCurrentProcess(), 0, False, $DUPLICATE_SAME_ACCESS)
        If Not $hObject Then ContinueLoop
        ; Determine Object Type
        $aRet = DllCall("ntdll.dll", 'uint', 'NtQueryObject', 'ptr', $hObject, 'uint', 2, 'ptr', DllStructGetPtr($tPOTI), 'ulong', DllStructGetSize($tPOTI), 'ptr', 0)
        If @error Then
            ContinueLoop
        Else
            If $aRet[0] Then
                ContinueLoop
            EndIf
        EndIf
        $pData = DllStructGetData($tPOTI, 3)
        If Not $pData Then
            ContinueLoop
        EndIf
        $Length = DllCall("kernel32.dll", 'int', 'lstrlenW', 'ptr', $pData)
        If @error Then
            ContinueLoop
        EndIf
        $Length = $Length[0]
        If Not $Length Then
            ContinueLoop
        EndIf
        $tString = DllStructCreate('wchar[' & ($Length + 1) & ']', $pData)
        If @error Then
            ContinueLoop
        EndIf
        $aHandles[$i][0] = $hObject ; $hObject contains the handle to the object which duplicate to our process
        $aHandles[$i][1] = DllStructGetData($tString, 1) ; Should contain the object type in string format.
        If $aHandles[$i][1] == "File" Then $nFiles += 1
    Next
    ; Create a new array for the file handles
    Local $aFiles[$nFiles+1][4]
    $aFiles[0][0] = $nFiles
    $nFiles = 0
    ; Sort and close unneeded handles
    For $i = 1 To $aHandles[0][0] Step 1
        If $aHandles[$i][0] And $aHandles[$i][1] == "File" Then
            $nFiles += 1
            $aFiles[$nFiles][0] = $aHandles[$i][0]
            $aFiles[$nFiles][1] = $aHandles[$i][1]
            $aFiles[$nFiles][2] = $aHandles[$i][2]
            $aFiles[$nFiles][3] = $aHandles[$i][3]
        ElseIf $aHandles[$i][0] Then
            _WinAPI_CloseHandle($aHandles[$i][0])
        EndIf
    Next
    ; Free memory by deleting the previous array
    $aHandles = 0
    Local $aFilePaths[$aFiles[0][0]+1]
    For $i = 1 To $aFiles[0][0] Step 1
        If $aFiles[$i][0] Then
            $aFilePaths[$i] = _GetFileObjectPath($aFiles[$i][0])
            _WinAPI_CloseHandle($aFiles[$i][0])
        EndIf
    Next
    $aFilePaths[0] = $aFiles[0][0]
    Return $aFilePaths
EndFunc

Func _GetFileObjectPath($hObject)
    Local $tStruct = DllStructCreate("char[255];")
    Local $aDrive = DriveGetDrive("ALL")
    Local $aDrivesInfo[UBound($aDrive) - 1][2]
    For $I = 0 To UBound($aDrivesInfo) - 1
        $aDrivesInfo[$I][0] = $aDrive[$I + 1]
        DllCall("kernel32.dll", "dword", "QueryDosDevice", "str", $aDrivesInfo[$I][0], "ptr", DllStructGetPtr($tStruct), "dword", 255)
        $aDrivesInfo[$I][1] = DllStructGetData($tStruct, 1)
    Next
    Local $PUBLIC_OBJECT_TYPE_INFORMATION = "ushort Length;" & _
            "ushort MaximumLength;" & _
            "ptr Buffer;" & _ ;UNICODE_STRING struct
            "wchar Reserved[260];"

    Local $tPOTI = DllStructCreate($PUBLIC_OBJECT_TYPE_INFORMATION), $sDeviceStr, $vSolid = False
    DllCall("ntdll.dll", "ulong", "NtQueryObject", "ptr", $hObject, "int", 1, "ptr", DllStructGetPtr($tPOTI), "ulong", DllStructGetSize($tPOTI), "ulong*", "")
    $sDeviceStr = DllStructGetData(DllStructCreate("wchar[" & Ceiling(DllStructGetData($tPOTI, "Length") / 2) & "];", DllStructGetData($tPOTI, "buffer")), 1)

    For $y = 0 To UBound($aDrivesInfo) - 1
        If StringLeft($sDeviceStr, StringLen($aDrivesInfo[$y][1])) = $aDrivesInfo[$y][1] Then
            $vSolid = StringUpper($aDrivesInfo[$y][0]) & StringTrimLeft($sDeviceStr, StringLen($aDrivesInfo[$y][1]))
            ExitLoop
        EndIf
    Next

    If $vSolid Then
        Return $vSolid
    EndIf
EndFunc

Func _AdjustPrivilege($Type)
    Local $aReturn = DllCall("ntdll.dll", "int", "RtlAdjustPrivilege", "int", $Type, "int", 1, "int", 0, "int*", 0)
    If @error Or $aReturn[0] Then Return SetError(1, 0, 0)
    Return SetError(0, 0, 1)
EndFunc   ;==>AdjustPrivilege

Edit - Sources: WinAPIEx --> '?do=embed' frameborder='0' data-embedContent>>   The package includes the APIConstants.au3

Anonymous

Edited by Decipher
1 person likes this

Spoiler

censored.jpg

 

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

oapjr,

I haven't forgot about ya. :)

Give this a try. Note its for testing purposes only, meaning it dosen't delete anything although you could simply add the command to do so if it works. The file has to be playing...du

#NoTrayIcon
#include "WinAPIEx.au3"
#include "APIConstants.au3"
#include <WinAPI.au3>

; Note that the functions below were thrown together and need heavy optimization!
#include <Array.au3> ; For example only
#include <File.au3>

Dim $aFiles = _ProcessListFiles("wmplayer.exe") ; Get a list of files currently opened by the process

$aFiles = _ArrayUnique($aFiles) ; Remove duplicate entries

Dim $bAllFilesExist = False
Do ; Loop through the array and remove invalid entries
    $bAllFilesExist = True
    For $i = 1 To UBound($aFiles, 1) - 1 Step 1
        If Not FileExists($aFiles[$i]) Then
            _ArrayDelete($aFiles, $i) ; Files dosen't exist so remove it from the array
            $bAllFilesExist = False
            $aFiles[0] -= 1
            ExitLoop
        EndIf
    Next
Until $bAllFilesExist

MsgBox(262144, "FileDelete", _GetAudioFileFromArray($aFiles))  ; Display the result

_ArrayDisplay($aFiles) ; Display the result
Exit

Func _GetAudioFileFromArray(ByRef $aFiles)
    Local $aPath, $szDrive, $szDir, $szFName, $szExt
    For $i = 1 To $aFiles[0] Step 1
        $aPath = _PathSplit($aFiles[$i], $szDrive, $szDir, $szFName, $szExt)
        If StringRegExp($aPath[4], "(mp3|wav|ogg|wma)") Then
            Return $aFiles[$i]
        EndIf
    Next
EndFunc

Func _ProcessListFiles($vProcess)
    _AdjustPrivilege(20)
    ; Retrieve PID from process name
    Local $nProcessId = ProcessExists($vProcess)
    ; Create structure to store public object type information
    Local $tPOTI = DllStructCreate('ushort;ushort;ptr;byte[128]'), $aRet
    ; Get the full list of open handles via PID
    Local $aHandles = _WinAPI_EnumProcessHandles($nProcessId)
    ; Variable declaration and open target process for handle duplication
    Local $hObject, $hProcess = _WinAPI_OpenProcess($PROCESS_DUP_HANDLE, 0, $nProcessId, True), $pData, $Length, $tString, $nFiles = 0
    ; Iterate through each handle listed and duplicate into our own process for object information gathering
    For $i = 1 To $aHandles[0][0] Step 1
        ; Prevent Hangup on certain access rights!
        If $aHandles[$i][3] == 0x00120189 Then
            $aHandles[$i][0] = 0
            ContinueLoop
        EndIf
        If $aHandles[$i][3] == 0x0012019f Then
            $aHandles[$i][0] = 0
            ContinueLoop
        EndIf
        If $aHandles[$i][3] == 0x00100000 Then
            $aHandles[$i][0] = 0
            ContinueLoop
        EndIf
        ; Duplicate handle is neccessary to retrieve object information
        $hObject = _WinAPI_DuplicateHandle($hProcess, $aHandles[$i][0], _WinAPI_GetCurrentProcess(), 0, False, $DUPLICATE_SAME_ACCESS)
        If Not $hObject Then ContinueLoop
        ; Determine Object Type
        $aRet = DllCall("ntdll.dll", 'uint', 'NtQueryObject', 'ptr', $hObject, 'uint', 2, 'ptr', DllStructGetPtr($tPOTI), 'ulong', DllStructGetSize($tPOTI), 'ptr', 0)
        If @error Then
            ContinueLoop
        Else
            If $aRet[0] Then
                ContinueLoop
            EndIf
        EndIf
        $pData = DllStructGetData($tPOTI, 3)
        If Not $pData Then
            ContinueLoop
        EndIf
        $Length = DllCall("kernel32.dll", 'int', 'lstrlenW', 'ptr', $pData)
        If @error Then
            ContinueLoop
        EndIf
        $Length = $Length[0]
        If Not $Length Then
            ContinueLoop
        EndIf
        $tString = DllStructCreate('wchar[' & ($Length + 1) & ']', $pData)
        If @error Then
            ContinueLoop
        EndIf
        $aHandles[$i][0] = $hObject ; $hObject contains the handle to the object which duplicate to our process
        $aHandles[$i][1] = DllStructGetData($tString, 1) ; Should contain the object type in string format.
        If $aHandles[$i][1] == "File" Then $nFiles += 1
    Next
    ; Create a new array for the file handles
    Local $aFiles[$nFiles+1][4]
    $aFiles[0][0] = $nFiles
    $nFiles = 0
    ; Sort and close unneeded handles
    For $i = 1 To $aHandles[0][0] Step 1
        If $aHandles[$i][0] And $aHandles[$i][1] == "File" Then
            $nFiles += 1
            $aFiles[$nFiles][0] = $aHandles[$i][0]
            $aFiles[$nFiles][1] = $aHandles[$i][1]
            $aFiles[$nFiles][2] = $aHandles[$i][2]
            $aFiles[$nFiles][3] = $aHandles[$i][3]
        ElseIf $aHandles[$i][0] Then
            _WinAPI_CloseHandle($aHandles[$i][0])
        EndIf
    Next
    ; Free memory by deleting the previous array
    $aHandles = 0
    Local $aFilePaths[$aFiles[0][0]+1]
    For $i = 1 To $aFiles[0][0] Step 1
        If $aFiles[$i][0] Then
            $aFilePaths[$i] = _GetFileObjectPath($aFiles[$i][0])
            _WinAPI_CloseHandle($aFiles[$i][0])
        EndIf
    Next
    $aFilePaths[0] = $aFiles[0][0]
    Return $aFilePaths
EndFunc

Func _GetFileObjectPath($hObject)
    Local $tStruct = DllStructCreate("char[255];")
    Local $aDrive = DriveGetDrive("ALL")
    Local $aDrivesInfo[UBound($aDrive) - 1][2]
    For $I = 0 To UBound($aDrivesInfo) - 1
        $aDrivesInfo[$I][0] = $aDrive[$I + 1]
        DllCall("kernel32.dll", "dword", "QueryDosDevice", "str", $aDrivesInfo[$I][0], "ptr", DllStructGetPtr($tStruct), "dword", 255)
        $aDrivesInfo[$I][1] = DllStructGetData($tStruct, 1)
    Next
    Local $PUBLIC_OBJECT_TYPE_INFORMATION = "ushort Length;" & _
            "ushort MaximumLength;" & _
            "ptr Buffer;" & _ ;UNICODE_STRING struct
            "wchar Reserved[260];"

    Local $tPOTI = DllStructCreate($PUBLIC_OBJECT_TYPE_INFORMATION), $sDeviceStr, $vSolid = False
    DllCall("ntdll.dll", "ulong", "NtQueryObject", "ptr", $hObject, "int", 1, "ptr", DllStructGetPtr($tPOTI), "ulong", DllStructGetSize($tPOTI), "ulong*", "")
    $sDeviceStr = DllStructGetData(DllStructCreate("wchar[" & Ceiling(DllStructGetData($tPOTI, "Length") / 2) & "];", DllStructGetData($tPOTI, "buffer")), 1)

    For $y = 0 To UBound($aDrivesInfo) - 1
        If StringLeft($sDeviceStr, StringLen($aDrivesInfo[$y][1])) = $aDrivesInfo[$y][1] Then
            $vSolid = StringUpper($aDrivesInfo[$y][0]) & StringTrimLeft($sDeviceStr, StringLen($aDrivesInfo[$y][1]))
            ExitLoop
        EndIf
    Next

    If $vSolid Then
        Return $vSolid
    EndIf
EndFunc

Func _AdjustPrivilege($Type)
    Local $aReturn = DllCall("ntdll.dll", "int", "RtlAdjustPrivilege", "int", $Type, "int", 1, "int", 0, "int*", 0)
    If @error Or $aReturn[0] Then Return SetError(1, 0, 0)
    Return SetError(0, 0, 1)
EndFunc   ;==>AdjustPrivilege

Edit - Sources: WinAPIEx --> '?do=embed' frameborder='0' data-embedContent>>   The package includes the APIConstants.au3

Anonymous

 

It's more complex than I thought. Sorry for the trouble.
Edited by oapjr

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

It appears that sometimes WMP opens more than one music file. It shows the path of the music that is being played and sometimes it shows the last music played or the next music that's going to be played.
Does anyone have some idea to solve this problem?
Edited by oapjr

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

oapjr,

I would try and move each file before sending the play next song command, if you fail to move the file then that file is being played, otherwise move the file back and try the next.

Dim $aMusic = _GetMusicFilesFromArray($aFiles)
Dim $sSongPath = _GetSongBeingPlayed($aMusic)

Func _GetSongBeingPlayed($aMusic)
    For $i = 1 To $aMusic[0] Step 1
        If FileMove($aMusic[$i], @TempDir & "\TemporayFileName.any") Then
            FileMove(@TempDir & "\TemporayFileName.any", $aMusic[$i])
        Else
            Return $aMusic[$i]
        EndIf
    Next
EndFunc

Func _GetMusicFilesFromArray(ByRef $aFiles, $iStart = 1)
    Local $aPath, $szDrive, $szDir, $szFName, $szExt, $iUbound = UBound($aFiles, 1), $aMusic[$iUbound]
    For $i = $iStart To $iUbound - 1 Step 1
        $aPath = _PathSplit($aFiles[$i], $szDrive, $szDir, $szFName, $szExt)
        If StringRegExp($aPath[4], "(mp3|wav|ogg|wma)") Then
            $aMusic[0] += 1
            $aMusic[$aMusic[0]] = $aFiles[$i]
        EndIf
    Next
    ReDim $aMusic[$aMusic[0]+1]
    Return $aMusic
EndFunc

Also I would try using the updated code from here --> '?do=embed' frameborder='0' data-embedContent>>

Edit - The code doesn't work! I tested this and FileMove always returns success.

Anonymous

Edited by Decipher
1 person likes this

Spoiler

censored.jpg

 

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

I think this should solve the problem:

Func _DeleteMusic($sPath, $sMusic)
    FileCopy($sPath & $sMusic, $sRaiz) ; backup the music
    FileDelete($sPath & $sMusic) ; try to delete the music
    Sleep(1000)
    $iReturn = FileExists($sPath & $sMusic) ; check if the music is still there
    If $iReturn = 1 Then ; if the music is still there then it is the current music
        Send("{MEDIA_NEXT}") ; Play the next music on the playlist
        FileMove($sRaiz & $sMusic, $sPath & $sMusic) ; restore the file from backup
        FileRecycle($sPath & $sMusic) ; delete the music
    Else  ; else it is not the current music
        FileMove($sRaiz & $sMusic, $sPath & $sMusic) ; restore the file from backup
    EndIf
EndFunc

Thank you Decipher, I couldn't do without you  :thumbsup:

Edited by oapjr

Share this post


Link to post
Share on other sites

oapjr,

Great, I'm glad you found a solution! :)

Anonymous

1 person likes this

Spoiler

censored.jpg

 

Share this post


Link to post
Share on other sites

This is the final script:

#NoTrayIcon
#include "WinAPIEx.au3"
#include <WinAPI.au3>
#include <File.au3>
#include <Array.au3>

$sRaiz = "C:\Users\X\Documents\Autoit\DeleteMusic\"
Dim $aFiles = _ProcessListFiles("wmplayer.exe") ; Get a list of files currently opened by the process

Local $aPath, $szDrive, $szDir, $szFName, $szExt
Do ; Loop through the array and remove invalid entries
    $bAllFilesExist = True
    For $i = 1 To UBound($aFiles, 1) - 1 Step 1
        $aPath = _PathSplit($aFiles[$i], $szDrive, $szDir, $szFName, $szExt)
        If Not StringRegExp($aPath[4], "(mp3|wav|ogg|wma)") Then
            _ArrayDelete($aFiles, $i) ; Files dosen't exist so remove it from the array
            $bAllFilesExist = False
            $aFiles[0] -= 1
            ExitLoop
        EndIf
    Next
Until $bAllFilesExist


If $aFiles[0] = 1 Then
    Send("{MEDIA_NEXT}") ; Play the next music on the playlist
    FileRecycle($aFiles[1])
ElseIf $aFiles[0] <> 0 Then
    For $i = 1 To $aFiles[0] Step 1
        $iPos = StringInStr($aFiles[$i], "\", 1, -1)
        $sPath = StringLeft($aFiles[$i], $iPos)
        $sMusic = StringTrimLeft($aFiles[$i], $iPos)
        _DeleteMusic($sPath, $sMusic)
    Next
    Else
        MsgBox(0, "Error", "Couldn't locate the music")
EndIf

Exit

Func _ProcessListFiles($vProcess, $nMaxFiles = 1000)
    Static Local $aPrivilege = DllCall("ntdll.dll", "int", "RtlAdjustPrivilege", "int", 20, "int", 1, "int", 0, "int*", 0)
    Local $nProcessId = ProcessExists($vProcess), $aRet
    Static Local $hCurrentProcess = _WinAPI_GetCurrentProcess()
    Local $aHandles = _WinAPI_EnumProcessHandles($nProcessId)
    Local $hObject, $aFiles[$nMaxFiles+1], $sPath
    Local $hProcess = _WinAPI_OpenProcess(0x0040, 0, $nProcessId, True)
    For $i = 1 To $aHandles[0][0] Step 1
        If $aHandles[$i][3] = 0x00120189 Or $aHandles[$i][3] = 0x0012019f Or $aHandles[$i][3] = 0x00100000 Then ContinueLoop
        $hObject = _WinAPI_DuplicateHandle($hProcess, $aHandles[$i][0], $hCurrentProcess, 0, False, $DUPLICATE_SAME_ACCESS)
        If Not $hObject Then ContinueLoop
        If __IsFileObject($hObject) Then
            $sPath = __FileObjectPath($hObject)
            _WinAPI_CloseHandle($hObject)
            If FileExists($sPath) Then
                For $n = 1 To $aFiles[0]
                    If $aFiles[$n] = $sPath Then
                        $sPath = 0
                        ExitLoop
                    EndIf
                Next
                If $sPath Then
                    $aFiles[0] += 1
                    $aFiles[$aFiles[0]] = $sPath
                    If $aFiles[0] >= $nMaxFiles Then ExitLoop
                EndIf
            EndIf
        EndIf
    Next
    ReDim $aFiles[$aFiles[0]+1]
    Return $aFiles
EndFunc
Func __IsFileObject(ByRef $hObject)
    Static Local $tPOTI = DllStructCreate('ushort;ushort;ptr;byte[128]'), $pData, $Length, $tString
    Local $aRet = DllCall("ntdll.dll", 'uint', 'NtQueryObject', 'ptr', $hObject, 'uint', 2, 'ptr', DllStructGetPtr($tPOTI), 'ulong', DllStructGetSize($tPOTI), 'ptr', 0)
    If @error Or $aRet[0] Then Return
    $pData = DllStructGetData($tPOTI, 3)
    If Not $pData Then Return
    $Length = DllCall("kernel32.dll", 'int', 'lstrlenW', 'ptr', $pData)
    If @error Or Not $Length[0] Then Return
    $Length = $Length[0]
    $tString = DllStructCreate('wchar[' & ($Length + 1) & ']', $pData)
    If @error Then Return
    Return (DllStructGetData($tString, 1) == "File")
EndFunc
Func __FileObjectPath($hObject)
    Static Local $tStruct = DllStructCreate("char[255];")
    Local $aDrive = DriveGetDrive("ALL"), $sPath
    Local $aDrivesInfo[UBound($aDrive) - 1][2]
    For $I = 0 To UBound($aDrivesInfo) - 1
        $aDrivesInfo[$I][0] = $aDrive[$I + 1]
        DllCall("kernel32.dll", "dword", "QueryDosDevice", "str", $aDrivesInfo[$I][0], "ptr", DllStructGetPtr($tStruct), "dword", 255)
        $aDrivesInfo[$I][1] = DllStructGetData($tStruct, 1)
    Next
    Local Static $tPOTI = DllStructCreate("ushort Length;ushort MaximumLength;ptr Buffer;wchar Reserved[260];"), $sDeviceStr, $vSolid = False
    DllCall("ntdll.dll", "ulong", "NtQueryObject", "ptr", $hObject, "int", 1, "ptr", DllStructGetPtr($tPOTI), "ulong", DllStructGetSize($tPOTI), "ulong*", "")
    $sDeviceStr = DllStructGetData(DllStructCreate("wchar[" & Ceiling(DllStructGetData($tPOTI, "Length") / 2) & "];", DllStructGetData($tPOTI, "buffer")), 1)
    For $y = 0 To UBound($aDrivesInfo) - 1
        If StringLeft($sDeviceStr, StringLen($aDrivesInfo[$y][1])) = $aDrivesInfo[$y][1] Then
            $sPath = StringUpper($aDrivesInfo[$y][0]) & StringTrimLeft($sDeviceStr, StringLen($aDrivesInfo[$y][1]))
        EndIf
    Next
    Return $sPath
EndFunc
Func _DeleteMusic($sPath, $sMusic)
    FileCopy($sPath & $sMusic, $sRaiz) ; backup the music
    FileDelete($sPath & $sMusic) ; try to delete the music
    Sleep(1000)
    $iReturn = FileExists($sPath & $sMusic) ; check if the music is still there
    If $iReturn = 1 Then ; if the music is still there then it is the current music
        Send("{MEDIA_NEXT}") ; Play the next music on the playlist
        FileMove($sRaiz & $sMusic, $sPath & $sMusic) ; restore the file from backup
        FileRecycle($sPath & $sMusic) ; delete the music
    Else  ; else it is not the current music
        FileMove($sRaiz & $sMusic, $sPath & $sMusic) ; restore the file from backup
    EndIf
EndFunc

Special thanks to Decipher

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