Jump to content
kisstom

list .mp3 file, double click to play

Recommended Posts

kisstom

Hi i would like to make a mp3 (or playlist, m3u) catalog program.

I can make a list of files with GUICtrlCreateListViewItem.  I just simple want to double click one of them and play with the default program (just like in explorer).

#include <GUiConstants.au3>
#include <File.au3>


$Form1 = GUICreate("Form1", 322, 438, 297, 131)

$MusicDir=FileSelectFolder("Please select a folder",@HomeDrive)

$ListView1 = GUICtrlCreateListView("Mp3 files at " & $MusicDir, 16, 4, 289, 413)

If @error Then Exit

$filesArray=_FileListToArray($MusicDir,"*.mp3")

For $i=1 To $filesArray[0]
    GUICtrlCreateListViewItem($filesArray[$i],$ListView1)
Next

GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg

        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

 

Edited by Melba23
Added code tags

Share this post


Link to post
Share on other sites
Melba23

kisstom,

Welcome to the AutoIt forum.

But please pay attention to where you post - the "Examples" section where you started this thread is clearly marked: "This is NOT a general support forum!".  I have moved it for you, but would ask you to be more careful in future.

And when you post code please use Code tags - see here how to do it.  Then you get a scrolling box and syntax colouring as you can see above now I have added the tags.

M23

 

  • Like 1

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
kisstom

Seems i'm done :D, my only problem now it's not contains subdirectory.

 

#include <File.au3>
#include <GuiConstants.au3>
#include <GuiListView.au3>



Global $DoubleClicked   = False
Global $width = 450
Global $height = 438

$Form1 = GUICreate("Form1", $width, $height)

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

$MusicDir=FileSelectFolder("Please select a folder",@HomeDrive)

$ListView1 = GUICtrlCreateListView("Mp3 files at " & $MusicDir, 15, 5, ($width - 30), ($height - 20))
_GUICtrlListView_SetColumnWidth($ListView1, 0,  ($width - 60)) ; set Column header width

If @error Then Exit

;$filesArray=_FileListToArray($MusicDir,"*.mp3") ; mp3 files only
$filesArray=_FileListToArray($MusicDir) ; all files

For $i=1 To $filesArray[0]
    GUICtrlCreateListViewItem($filesArray[$i],$ListView1)
Next

GUISetState()


While GUIGetMsg() <> -3
    Sleep(10)
    If $DoubleClicked Then
        DoubleClickFunc()
        $DoubleClicked = False
    EndIf
WEnd

Func DoubleClickFunc()

    $runpath = ($MusicDir & "\" & GUICtrlRead(GUICtrlRead($ListView1)))
    $runpath = StringTrimRight ($runpath, 1) ;remove last character (there is a "|" character at the end i don't know why)
    ;ToolTip ($runpath) ; just to test
    ;ToolTip("Double Clicked: " & $MusicDir & "\" & GUICtrlRead(GUICtrlRead($ListView1)))
    ;Sleep (2000)
    ;ToolTip("")
    ShellExecute ($runpath) ; runs the double clicked file
EndFunc

Func WM_NOTIFY($hWnd, $MsgID, $wParam, $lParam)
    Local $tagNMHDR, $event, $hwndFrom, $code
    $tagNMHDR = DllStructCreate("int;int;int", $lParam)
    If @error Then Return 0
    $code = DllStructGetData($tagNMHDR, 3)
    If $wParam = $ListView1 And $code = -3 Then $DoubleClicked = True
    Return $GUI_RUNDEFMSG
EndFunc

 

Edited by kisstom
  • Like 1

Share this post


Link to post
Share on other sites
Melba23

kisstom,

my only problem now it's not contains subdirectory

Use _FileListToArrayRec to get files from within subfolders on the path.

M23 

  • Like 1

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
Chimp

here another way...

#include <GuiListView.au3>

#include <GUiConstants.au3>
#include <File.au3>

$Form1 = GUICreate("Form1", 322, 438, 297, 131)

Global $MusicDir = FileSelectFolder("Please select a folder", @HomeDrive)

$ListView1 = GUICtrlCreateListView("Mp3 files at " & $MusicDir, 16, 4, 289, 413)

If @error Then Exit

$filesArray = _FileListToArray($MusicDir, "*.mp3")

For $i = 1 To $filesArray[0]
    GUICtrlCreateListViewItem($filesArray[$i], $ListView1)
Next

GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_NOTIFY, "_Check_Click") ; Register a user defined function for a known Windows Message ID (WM_MSG). ---------+
;                                                                                                                               |
; WM_NOTIFY event handler for click example: http://www.autoitscript.com/forum/topic/143900-listview-onclick/#entry1013670  <---+
Func _Check_Click($hWnd, $iMsg, $iwParam, $ilParam)
    Local $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    Local $hList = GUICtrlGetHandle($ListView1)

    If HWnd(DllStructGetData($tNMHDR, "hWndFrom")) = $hList And DllStructGetData($tNMHDR, "Code") = $NM_CLICK Then ; event is from $hList and it is a $NM_CLICK
        ; is a Click
        ; manage click here
    EndIf

    ; what follows will check if it is a doubleClick and if is comming from the listview
    If HWnd(DllStructGetData($tNMHDR, "hWndFrom")) = $hList And DllStructGetData($tNMHDR, "Code") = $NM_DBLCLK Then ; event is from $hList and it is a $NM_DBLCLK
        ; is a DoubleClick
        $aLV_Click_Info = _GUICtrlListView_SubItemHitTest($hList)
        If $aLV_Click_Info[0] <> -1 Then
            ConsoleWrite("DoubleClick on " & _GUICtrlListView_GetItemText($hList, $aLV_Click_Info[0]) & @CRLF)
        Else
            ConsoleWrite("DoubleClick on an empty row" & @CRLF)
        EndIf
        ConsoleWrite($MusicDir & "\" & _GUICtrlListView_GetItemText($hList, $aLV_Click_Info[0]) & @CRLF)
        SoundPlay("")
        SoundPlay($MusicDir & "\" & _GUICtrlListView_GetItemText($hList, $aLV_Click_Info[0]))
    EndIf
    Return ; $GUI_RUNDEFMSG
EndFunc   ;==>_Check_Click

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

 

Edited by Chimp
  • Like 1

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites
kisstom

Thx Melba23 and Chimp, i'll play with this :)

 

Share this post


Link to post
Share on other sites
kisstom

kisstom,

Use _FileListToArrayRec to get files from within subfolders on the path.

M23 

​ Ok, now i get all the files i need, thank you. I want to make a program that list all *.m3u (winamp playlist file) from the sected directories, double click on of them to play music.

It's working now BUT i want to list only *.m3u filename not the full path. In this case i not get the full path of the file if i double click on an item.

My idea is to store the full path in another variable (in the same order) and list the file names only. Is there a way to get the number of double clicked item with GUICtrlRead? Then i can get the full path from the another variable and run the file.

Sorry, my English is not on the top, i hope you understand what i want.

Share this post


Link to post
Share on other sites
Chimp

to get the number of double clicked item have a look to the  _GUICtrlListView_SubItemHitTest function

and to get the text at that item number have a look to the  _GUICtrlListView_GetItemText

have a look in my previous post on how I used those functions

  • Like 1

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites
kisstom

Thank you Chimp, it's working.

Here is the code if someone interested:

#include <GuiListView.au3>
#include <GUiConstants.au3>
#include <File.au3>

Global $width = 500
Global $height = 438
$Form1 = GUICreate("Form1", $width, $height)

Global $MusicDir = FileSelectFolder("Please select a folder", @HomeDrive)

$ListView1 = GUICtrlCreateListView("Playlist files at " & $MusicDir, 15, 5, ($width - 30), ($height - 20))
_GUICtrlListView_SetColumnWidth($ListView1, 0,  ($width - 60)) ; set Column header width

If @error Then Exit

$filesArray=_FileListToArrayRec($MusicDir, "*.m3u", 1, 1, 2, 1) ; all files, Relative to initial path (last "1"), File/folder name only (last "0")

For $i = 1 To $filesArray[0]

    ;GUICtrlCreateListViewItem($filesArray[$i], $ListView1)
    GUICtrlCreateListViewItem((StringRegExpReplace($filesArray[$i], "^.*\\|\..*$", "")), $ListView1) ; display filenames only
    ;https://www.autoitscript.com/forum/topic/115992-extracting-just-the-filename-and-extension-from-a-full-path/

Next

GUISetState(@SW_SHOW)

GUIRegisterMsg($WM_NOTIFY, "_Check_Click") ; Register a user defined function for a known Windows Message ID (WM_MSG). ---------+
;                                                                                                                               |
; WM_NOTIFY event handler for click example: http://www.autoitscript.com/forum/topic/143900-listview-onclick/#entry1013670  <---+
Func _Check_Click($hWnd, $iMsg, $iwParam, $ilParam)
    Local $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    Local $hList = GUICtrlGetHandle($ListView1)

    If HWnd(DllStructGetData($tNMHDR, "hWndFrom")) = $hList And DllStructGetData($tNMHDR, "Code") = $NM_CLICK Then ; event is from $hList and it is a $NM_CLICK
        ; is a Click
        ; manage click here
    EndIf

    ; what follows will check if it is a doubleClick and if is comming from the listview
    If HWnd(DllStructGetData($tNMHDR, "hWndFrom")) = $hList And DllStructGetData($tNMHDR, "Code") = $NM_DBLCLK Then ; event is from $hList and it is a $NM_DBLCLK
        ; is a DoubleClick
        $aLV_Click_Info = _GUICtrlListView_SubItemHitTest($hList)
        If $aLV_Click_Info[0] <> -1 Then
            ;ToolTip($aLV_Click_Info[0]) ;number of item
            ;ToolTip($filesArray[$aLV_Click_Info[0]+1]) ;path
            ;ToolTip("DoubleClick on " & _GUICtrlListView_GetItemText($hList, $aLV_Click_Info[0]) & @CRLF)
            ;ToolTip($MusicDir & "\" & ($filesArray[$aLV_Click_Info[0]+1])) ; test the full path
            ShellExecute ($MusicDir & "\" & ($filesArray[$aLV_Click_Info[0]+1]))

        Else
            ;ToolTip("DoubleClick on an empty row" & @CRLF)
        EndIf

    EndIf
    Return ; $GUI_RUNDEFMSG
EndFunc   ;==>_Check_Click

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

 

Edited by kisstom

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

×