Jump to content

How to play a selected item in a listview ?


LIMITER
 Share

Recommended Posts

Hy all ! How can i play the file which is selected in the listview ??? - Thanks a lot !!

Here is the code :

#include <GUIConstants.au3>
#include <Sound.au3>
#Include <GuiListView.au3>

InetGet("http://img177.imageshack.us/img177/4310/lmplogomx0.jpg",@TempDir & "\lmplogo.jpg", 1, 1)
While @InetGetActive
  TrayTip("Welcome " & @UserName & " !","Please wait while LMP is loading ...", 1, 1)
  Sleep(1500)
Wend
InetGet("http://www.imagehosting.com/out.php/i1478222_stop.bmp",@TempDir & "\stopb.bmp", 1, 1)
While @InetGetActive
  TrayTip("Welcome " & @UserName & " !","Please wait while LMP is loading ...", 1, 1)
  Sleep(1500)
Wend
InetGet("http://www.imagehosting.com/out.php/i1478172_pause.bmp",@TempDir & "\pauseb.bmp", 1, 1)
While @InetGetActive
  TrayTip("Welcome " & @UserName & " !","Please wait while LMP is loading ...", 1, 1)
  Sleep(1500)
Wend
InetGet("http://www.imagehosting.com/out.php/i1478210_play.bmp",@TempDir & "\playb.bmp", 1, 1)
While @InetGetActive
  TrayTip("Welcome " & @UserName & " !","Please wait while LMP is loading ...", 1, 1)
  Sleep(1500)
Wend
InetGet("http://www.imagehosting.com/out.php/i1478238_resume.bmp",@TempDir & "\resumeb.bmp", 1, 1)
While @InetGetActive
  TrayTip("Welcome " & @UserName & " !","Please wait while LMP is loading ...", 1, 1)
  Sleep(1500)
Wend
GUICreate("L|M|TER Media Player - ©2008 L|M|TER",650, 160)
GUISetState()
GUICtrlCreatePic(@TempDir & "\lmplogo.jpg", 29.5, 5, 391, 63)
GUICtrlCreateLabel("Select a file to play :",5,80)
$hWnd = WinGetHandle("L|M|TER Media Player - ©2008 L|M|TER")
$input = GUICtrlCreateInput("",5,100,250)
$browse = GUICtrlCreateButton(" Browse ... ",265,98)
$play = GUICtrlCreateButton("",5,125,30,30,$BS_BITMAP)
$stop = GUICtrlCreateButton("",42,125,30,30,$BS_BITMAP)
$pause = GUICtrlCreateButton("",80,125,33,30,$BS_BITMAP)
$resume = GUICtrlCreateButton("",121,125,33,30,$BS_BITMAP)
$about = GUICtrlCreateButton(" About LMP ",160,125)
$add = GUICtrlCreateButton("Add ",417,30)
$rem = GUICtrlCreateButton("Rem",417,55)
$pplay = GUICtrlCreateButton("Play ", 417,80)
$status = GUICtrlCreateLabel("Status : FILE NOT OPENED", 300,135)
$playlist = _GUICtrlListView_Create($hWnd,"LMP Playlist",450,5,195)
GUICtrlSetImage($play,@TempDir & "\playb.bmp")
GUICtrlSetImage($pause,@TempDir & "\pauseb.bmp")
GUICtrlSetImage($stop,@TempDir & "\stopb.bmp")
GUICtrlSetImage($resume,@TempDir & "\resumeb.bmp")
TrayTip("L|M|TER MEDIA PLAYER", "File not opened ...", 2, 1)
$sound = _SoundOpen("")

Func browse()
    $file = FileOpenDialog("Select a file to play ...", @HomeDrive,"Music Files (*.mp3;*.wav)")
    If @error = 1 Then MsgBox(32,"L|M|TER Media Player","Please select a file !")
    GUICtrlSetData($input,$file)
    $sound = _SoundOpen($file)
    GUICtrlSetData($status,"Status : STOPPED ...")
    TrayTip("L|M|TER MEDIA PLAYER", "Stopped ...", 2, 1)
EndFunc

Func play()
    _SoundPlay($sound)
    GUICtrlSetData($status,"Status : PLAYING ...")
    TrayTip("L|M|TER MEDIA PLAYER", "Playing ...", 2, 1)
EndFunc

Func stop()
    _SoundStop($sound)
    GUICtrlSetData($status,"Status : STOPPED ...")
    TrayTip("L|M|TER MEDIA PLAYER", "Stopped ...", 2, 1)
EndFunc

Func pause()
    _SoundPause($sound)
    GUICtrlSetData($status,"Status : PAUSED ...")
    TrayTip("L|M|TER MEDIA PLAYER", "Paused ...", 2, 1)
EndFunc

Func resume()
    _SoundResume($sound)
    GUICtrlSetData($status,"Status : PLAYING ...")
    TrayTip("L|M|TER MEDIA PLAYER", "Playing ...", 2, 1)
EndFunc

Func about()
    MsgBox(32,"About", "L|M|TER MEDIA PLAYER" & @CR & "v. 1.0.2" & @CR & "Copyright ©2008 L|M|TER")
EndFunc

Func add()
    $song = FileOpenDialog("Add a file to playlist", @HomeDrive,"Music Files (*.mp3;*.wav)")
    _GUICtrlListView_AddItem($playlist,$song)
EndFunc

Func rem()
    _GUICtrlListView_DeleteItemsSelected($playlist)
EndFunc

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
            _SoundClose($sound)
        Case $msg = $browse
            Call("browse")
        Case $msg = $play
            Call("play")
        Case $msg = $stop
            Call("stop")
        Case $msg = $pause
            Call("pause")
        Case $msg = $resume
            Call("resume")
        Case $msg = $about
            Call("about")
        Case $msg = $add
            Call("add")
        Case $msg = $rem
            Call("rem")
            EndSelect
Wend
Link to comment
Share on other sites

Heard of the helpfile?

Look in it for _GuiCtrlList_ and look through the functions.

THX for the post - because i can't find that function

Oh ! and one thing ... my control isn't a LIST BOX is a LIST VIEW !! :)

P.S - i searched the helpfile before but didn't find the function , so excuse me

Edited by LIMITER
Link to comment
Share on other sites

what's the code to get the selected item ??

GuiCtrlRead($control)

Heard of the helpfile?

Look in it for _GuiCtrlList_ and look through the functions.

Arg...get your own...this one is mine

I can do signature me.

Link to comment
Share on other sites

i'm now trying to create a listview using GUICtrlCreateListView not _GUICtrlListView_create how i created it before

i will notice you if it works or not .

I used the guictrlread function but that is not returning the text of the item , it returns only the ID .What function should i use to be able to play the item in the listview ?

#include <GUIConstants.au3>
#include <Sound.au3>
#Include <GuiListView.au3>

InetGet("http://img177.imageshack.us/img177/4310/lmplogomx0.jpg",@TempDir & "\lmplogo.jpg", 1, 1)
While @InetGetActive
  TrayTip("Welcome " & @UserName & " !","Please wait while LMP is loading ...", 1, 1)
  Sleep(1500)
Wend
InetGet("http://www.imagehosting.com/out.php/i1478222_stop.bmp",@TempDir & "\stopb.bmp", 1, 1)
While @InetGetActive
  TrayTip("Welcome " & @UserName & " !","Please wait while LMP is loading ...", 1, 1)
  Sleep(1500)
Wend
InetGet("http://www.imagehosting.com/out.php/i1478172_pause.bmp",@TempDir & "\pauseb.bmp", 1, 1)
While @InetGetActive
  TrayTip("Welcome " & @UserName & " !","Please wait while LMP is loading ...", 1, 1)
  Sleep(1500)
Wend
InetGet("http://www.imagehosting.com/out.php/i1478210_play.bmp",@TempDir & "\playb.bmp", 1, 1)
While @InetGetActive
  TrayTip("Welcome " & @UserName & " !","Please wait while LMP is loading ...", 1, 1)
  Sleep(1500)
Wend
InetGet("http://www.imagehosting.com/out.php/i1478238_resume.bmp",@TempDir & "\resumeb.bmp", 1, 1)
While @InetGetActive
  TrayTip("Welcome " & @UserName & " !","Please wait while LMP is loading ...", 1, 1)
  Sleep(1500)
Wend
GUICreate("L|M|TER Media Player - ©2008 L|M|TER",650, 160)
GUISetState()
GUICtrlCreatePic(@TempDir & "\lmplogo.jpg", 29.5, 5, 391, 63)
GUICtrlCreateLabel("Select a file to play :",5,80)
$hWnd = WinGetHandle("L|M|TER Media Player - ©2008 L|M|TER")
$input = GUICtrlCreateInput("",5,100,250)
$browse = GUICtrlCreateButton(" Browse ... ",265,98)
$play = GUICtrlCreateButton("",5,125,30,30,$BS_BITMAP)
$stop = GUICtrlCreateButton("",42,125,30,30,$BS_BITMAP)
$pause = GUICtrlCreateButton("",80,125,33,30,$BS_BITMAP)
$resume = GUICtrlCreateButton("",121,125,33,30,$BS_BITMAP)
$about = GUICtrlCreateButton(" About LMP ",160,125)
$add = GUICtrlCreateButton("Add ",417,30)
$rem = GUICtrlCreateButton("Rem",417,55)
$pplay = GUICtrlCreateButton("Play ", 417,80)
$status = GUICtrlCreateLabel("Status : FILE NOT OPENED", 300,135)
$playlist = GUICtrlCreateListView("LMP Playlist",450,5,195,150)
GUICtrlSetImage($play,@TempDir & "\playb.bmp")
GUICtrlSetImage($pause,@TempDir & "\pauseb.bmp")
GUICtrlSetImage($stop,@TempDir & "\stopb.bmp")
GUICtrlSetImage($resume,@TempDir & "\resumeb.bmp")
TrayTip("L|M|TER MEDIA PLAYER", "File not opened ...", 2, 1)
$sound = _SoundOpen("")

Func browse()
    $file = FileOpenDialog("Select a file to play ...", @HomeDrive,"Music Files (*.mp3;*.wav)")
    If @error = 1 Then MsgBox(32,"L|M|TER Media Player","Please select a file !")
    GUICtrlSetData($input,$file)
    $sound = _SoundOpen($file)
    GUICtrlSetData($status,"Status : STOPPED ...")
    TrayTip("L|M|TER MEDIA PLAYER", "Stopped ...", 2, 1)
EndFunc

Func play()
    _SoundPlay($sound)
    If _SoundPlay = "" Then MsgBox(32,"L|M|TER MEDIA PLAYER","Please select a file to play.")
    GUICtrlSetData($status,"Status : PLAYING ...")
    TrayTip("L|M|TER MEDIA PLAYER", "Playing ...", 2, 1)
EndFunc

Func stop()
    _SoundStop($sound)
    GUICtrlSetData($status,"Status : STOPPED ...")
    TrayTip("L|M|TER MEDIA PLAYER", "Stopped ...", 2, 1)
EndFunc

Func pause()
    _SoundPause($sound)
    GUICtrlSetData($status,"Status : PAUSED ...")
    TrayTip("L|M|TER MEDIA PLAYER", "Paused ...", 2, 1)
EndFunc

Func resume()
    _SoundResume($sound)
    GUICtrlSetData($status,"Status : PLAYING ...")
    TrayTip("L|M|TER MEDIA PLAYER", "Playing ...", 2, 1)
EndFunc

Func about()
    MsgBox(32,"About", "L|M|TER MEDIA PLAYER" & @CR & "v. 1.0.2" & @CR & "Copyright ©2008 L|M|TER")
EndFunc

Func add()
    $song = FileOpenDialog("Add a file to playlist", @HomeDrive,"Music Files (*.mp3;*.wav)")
    GUICtrlCreateListViewItem($song,$playlist)
EndFunc

Func rem()
    $selected = GuiCtrlRead($playlist)
    GUICtrlDelete($selected)
EndFunc

Func pplay()
    $selected = GuiCtrlRead($playlist)
    MsgBox(32,"",$selected)
EndFunc

While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE
            ExitLoop
            _SoundClose($sound)
        Case $msg = $browse
            Call("browse")
        Case $msg = $play
            Call("play")
        Case $msg = $stop
            Call("stop")
        Case $msg = $pause
            Call("pause")
        Case $msg = $resume
            Call("resume")
        Case $msg = $about
            Call("about")
        Case $msg = $add
            Call("add")
        Case $msg = $rem
            Call("rem")
        Case $msg = $pplay
            Call("pplay")
            EndSelect
Wend
Link to comment
Share on other sites

_SoundPlay()

i found the function that get's the text from the item but it has a trailing "|" it look like this

$something = GuiCtrlRead(the id of the selected item)

msgbox(32,"",$something)

and in the msgbox is the text : for example "c:\music\musicfile.mp3|"

how could i remove that |

Link to comment
Share on other sites

i found the function that get's the text from the item but it has a trailing "|" it look like this

$something = GuiCtrlRead(the id of the selected item)

msgbox(32,"",$something)

and in the msgbox is the text : for example "c:\music\musicfile.mp3|"

how could i remove that |

If StingInStr($something, "|") then StringTrimRight($Something,1)
Link to comment
Share on other sites

I used the guictrlread function but that is not returning the text of the item , it returns only the ID .What function should i use to be able to play the item in the listview ?

_GUICtrlListView_GetNextItem()

and then

_GUICtrlListView_GetItemText()

You must use latest AutoIt 3.2.10

Look into Helpfile for details/examples.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...