Sign in to follow this  
Followers 0
Hawkwing

forward/backward with sound.au3

9 posts in this topic

I would prefer if I didn't have to use the 00:00:00 style of seeking that sound.au3 uses, it would be much easier to be able to simply have a way to go forward/backward $x seconds. Also, does anyone know how to adjust the volume level for just a sound being played with _soundplay?


The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Share this post


Link to post
Share on other sites



I would prefer if I didn't have to use the 00:00:00 style of seeking that sound.au3 uses, it would be much easier to be able to simply have a way to go forward/backward $x seconds.

You can use _TimeToTicks() and _TicksToTime for that().... I feel like I have said that before.... Hmm here it is.

Also, does anyone know how to adjust the volume level for just a sound being played with _soundplay?

Yes I know :)

Here is my modified version of _SoundVolume() (original here) that works from AutoIt 3.2.13.10 (or something like that) and up. You can "see"/hear it in use in my EMP.

As a bonus I am throwing in the updated _SoundSpeed() too :)

Func _SoundSpeed($sSnd_id, $Speed)  ;$Speed: 0 - 2267, 1000= normal,    By: Kip, topic 67021
    Local $iRet
    If StringInStr($sSnd_id[0],'!') Then Return SetError(3, 0, 0); invalid file/alias
    if $Speed < 0 or $Speed > 2267 Then Return SetError(1, 0, 0)
    $iRet = __mciSendString("set " & FileGetShortName($sSnd_id[0]) & " speed "&$Speed)
    If $iRet = 0 Then
        Return 1
    Else
        Return SetError(1, 0, 0)
    EndIf
EndFunc;==>_SoundSpeed

Func _SoundVolume($sSnd_id, $Volume)    ;$Volume: 0 - 1000, 1000= normal,   By: Kip, topic 67021
    Local $iRet; Declare variables
    If StringInStr($sSnd_id[0], '!') Then Return SetError(3, 0, 0); invalid file/alias
    If $Volume < 0 Or $Volume > 1000 Then Return SetError(1, 0, 0)
    $iRet = _mciSendString2("setaudio " & FileGetShortName($sSnd_id[0]) & " volume to " & $Volume)
    If $iRet = 0 Then; return
        Return 1
    Else
        Return SetError(1, 0, 0)
    EndIf
EndFunc   ;==>_SoundVolume

Func _mciSendString2($String9)
    Local $iRet
    $iRet = DllCall("winmm.dll", "int", "mciSendStringA", "str", $String9, "str", "", "int", 65534, "hwnd", 0)
    If Not @error Then Return $iRet[2]
EndFunc   ;==>_mciSendString

Share this post


Link to post
Share on other sites

Wow, thanks!


The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Share this post


Link to post
Share on other sites

Wow, thanks!

No problem. The source for EMP is not ready for general consumption (I always planned to release the source some day) but until then I will happily release most portions of it if asked, so don't hesitate if there's anything in it that catches your interest.

Now if you don't mind me asking, what kind of application are you creating? A music player?

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Yep, music player. Normally I just use Windows Media Player, but I would like to be able to have songs repeat a different number of times. So if I like a song a lot, I could have it repeat 3 times, and if I didn't like another quite that much, I could have it repeat 2 times. I'll probably use a listview with a column for # of repeats, a column for current repeat, and a column for song name. I probably won't have any icons, since I'm not even sure if I want to do much with it. If anyone has suggestions I'd be happy to take them :)

Edited by Hawkwing

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Share this post


Link to post
Share on other sites

I'm having a bit of trouble with the seeking, I want to be able to click the button once, and it goes 2x speed, again and it goes 4x, etc.

This is what I have, but it doesn't seem to do anything.

If TimerDiff($timer) > 1000 Then
    Local $hour, $min, $sec
    $temp = _SoundPos($sounds[$currentsound], 2) + $seekspeed * 1000
    _TicksToTime($temp, $hour, $min, $sec)
    _SoundSeek($sounds[$currentsound], $hour, $min, $sec)
    $timer = TimerInit()
EndIf

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

This is the total script so far. The FF doesn't work, and the FB doesn't do anything, but it's working so far except the FF.

#include<guiconstants.au3>
#include<buttonconstants.au3>
#include<sound.au3>
#include<misc.au3>
#include<date.au3>

_Singleton("Auto Player")

#NoTrayIcon

Opt("guioneventmode", 1)

#Region GUI
$autoplayer = GUICreate("Auto Player", 218, 278)
GUISetOnEvent($GUI_EVENT_CLOSE, "close")
GUISetBkColor(0xFFFFFF)

$menufile = GUICtrlCreateMenu("File")
$menufileopen = GUICtrlCreateMenuItem("Open", $menufile)
GUICtrlSetOnEvent(-1, "open")
$menufileexit = GUICtrlCreateMenuItem("Exit", $menufile)
GUICtrlSetOnEvent(-1, "close")

$menuoptions = GUICtrlCreateMenu("Options")
$menuoptionsrepeat = GUICtrlCreateMenuItem("Repeat", $menuoptions)
GUICtrlSetOnEvent(-1, "repeat")

$playpause = GUICtrlCreateButton("Play", 75, 5, 32, 32, $BS_BITMAP)
GUICtrlSetOnEvent(-1, "playpause")
$stop = GUICtrlCreateButton("Stop", 110, 5, 32, 32, $BS_BITMAP)
GUICtrlSetOnEvent(-1, "stop")
$fb = GUICtrlCreateButton("FB", 40, 5, 32, 32, $BS_BITMAP)
GUICtrlSetOnEvent(-1, "fastbackward")
$ff = GUICtrlCreateButton("FF", 145, 5, 32, 32, $BS_BITMAP)
GUICtrlSetOnEvent(-1, "fastforward")
$previous = GUICtrlCreateButton("P", 5, 5, 32, 32, $BS_BITMAP)
GUICtrlSetOnEvent(-1, "previoustrack")
$next = GUICtrlCreateButton("N", 180, 5, 32, 32, $BS_BITMAP)
GUICtrlSetOnEvent(-1, "nexttrack")
$tempbtn = GUICtrlCreateButton("temp", 110, 40, 100, 20)
GUICtrlSetOnEvent(-1, "tempfunc")
$timedisplay = GUICtrlCreateLabel("00:00:00/00:00:00", 5, 40, 150, 20)

$listview = GUICtrlCreateListView("# of Repeats|Current Repeat|Song", 5, 65, 208, 190)

Dim $autoplayer_AccelTable[1][2] = [["{SPACE}", $playpause]]
GUISetAccelerators($autoplayer_AccelTable)
GUISetState()
#EndRegion GUI
#EndRegion GUI

;~ $playing = 0 - stopped, 1 - playing, 2 - paused, 3 - seeking forward, 4 - seeking backward
Global $playing, $currentsound, $repeat, $seekspeed, $currentrepeat, $listviewitem
Dim $sounds[1], $repeats[1]

$timer = TimerInit()
While 1
    If $playing = 1 Then
        GUICtrlSetData($timedisplay, _SoundPos($sounds[$currentsound]) & "/" & _SoundLength($sounds[$currentsound]))
        If _SoundPos($sounds[$currentsound], 2) + 100 > _SoundLength($sounds[$currentsound], 2) Then
            _SoundStop($sounds[$currentsound])
            If $currentrepeat = $repeats[$currentsound] Then
                $currentrepeat = 1
                GUICtrlSetData($listviewitem[$currentsound], $repeats[$currentsound] & "|" & 0 & "|" & $sounds[$currentsound])
                GUICtrlSetBkColor($listviewitem[$currentsound], 0xFFFFFF)
                If $currentsound < UBound($sounds) - 1 Then
                    $currentsound += 1
                    _SoundPlay($sounds[$currentsound])
                ElseIf $repeat = 1 Then
                    $currentsound = 2
                    _SoundPlay($sounds[$currentsound])
                Else
                    $currentrepeat = $repeats[$currentsound]
                    stop()
                EndIf
                GUICtrlSetBkColor($listviewitem[$currentsound], 0xFFFF00)
            Else
                $currentrepeat += 1
                _SoundPlay($sounds[$currentsound])
            EndIf
            GUICtrlSetData($listviewitem[$currentsound], $repeats[$currentsound] & "|" & $currentrepeat & "|" & $sounds[$currentsound])
        EndIf
    ElseIf $playing = 3 Then
        If TimerDiff($timer) > 1000 Then
            Local $hour, $min, $sec
            $temp = _SoundPos($sounds[$currentsound], 2) + $seekspeed * 1000
            _TicksToTime($temp, $hour, $min, $sec)
            _SoundSeek($sounds[$currentsound], $hour, $min, $sec)
            $timer = TimerInit()
        EndIf
    ElseIf $playing = 4 Then
    EndIf
WEnd

Func tempfunc()
    For $i = 2 To UBound($listviewitem) - 1
        If $listviewitem[$i] = GUICtrlRead($listview) Then
            $temp = 0
            If $currentsound = $i Then $temp = $currentrepeat
            $repeats[$i] += 1
            GUICtrlSetData($listviewitem[$i], $repeats[$i] & "|" & $temp & "|" & $sounds[$i])
        EndIf
    Next
EndFunc

Func open()
    $path = FileOpenDialog("Open Files", "D:\Audio", "Sounds (*.mp3; *.wav)", 7)
    If $path = "" Then Return
    If StringInStr($path, "|") Then
        $sounds = StringSplit($path, "|")
    Else
        Dim $sounds[3]
        $sounds[2] = $path
    EndIf
    Global $listviewitem[UBound($sounds)], $repeats[UBound($sounds)]
    For $i = 2 To UBound($sounds) - 1
        $listviewitem[$i] = GUICtrlCreateListViewItem(1 & "|" & 0 & "|" & $sounds[$i], $listview)
        $repeats[$i] = 1
    Next
    $currentsound = 2
    $currentrepeat = 1
    GUICtrlSetData($listviewitem[$currentsound], $repeats[$currentsound] & "|" & $currentrepeat & "|" & $sounds[$currentsound])
    GUICtrlSetBkColor($listviewitem[$currentsound], 0xFFFF00)
    _SoundPlay($sounds[2])
    $playing = 1
    GUICtrlSetData($playpause, "Pause")
EndFunc

Func playpause()
    If $playing = 1 Then
        _SoundPause($sounds[$currentsound])
        $playing = 2
        GUICtrlSetData($playpause, "Play")
    ElseIf $playing = 2 Then
        _SoundResume($sounds[$currentsound])
        GUICtrlSetData($playpause, "Pause")
        $playing = 1
    ElseIf $playing = 0 Then
        _SoundPlay($sounds[$currentsound])
        GUICtrlSetData($playpause, "Pause")
        $playing = 1
    EndIf
EndFunc

Func stop()
    $playing = 0
    _SoundStop($sounds[$currentsound])
    GUICtrlSetData($playpause, "Play")
    GUICtrlSetData($timedisplay, "00:00:00/" & _SoundLength($sounds[$currentsound]))
EndFunc

Func repeat()
    If $repeat = 0 Then
        $repeat = 1
        GUICtrlSetState($menuoptionsrepeat, $GUI_CHECKED)
    ElseIf $repeat = 1 Then
        $repeat = 0
        GUICtrlSetState($menuoptionsrepeat, $GUI_UNCHECKED)
    EndIf
EndFunc

Func nexttrack()
    _SoundStop($sounds[$currentsound])
    If $currentrepeat = $repeats[$currentsound] Then
        $currentrepeat = 1
        GUICtrlSetData($listviewitem[$currentsound], $repeats[$currentsound] & "|" & 0 & "|" & $sounds[$currentsound])
        GUICtrlSetBkColor($listviewitem[$currentsound], 0xFFFFFF)
        If $currentsound < UBound($sounds) - 1 Then
            $currentsound += 1
        Else
            $currentsound = 2
        EndIf
        GUICtrlSetBkColor($listviewitem[$currentsound], 0xFFFF00)
    Else
        $currentrepeat += 1
    EndIf
    GUICtrlSetData($listviewitem[$currentsound], $repeats[$currentsound] & "|" & $currentrepeat & "|" & $sounds[$currentsound])
    _SoundPlay($sounds[$currentsound])
EndFunc

Func previoustrack()
    _SoundStop($sounds[$currentsound])
    If $currentrepeat = 1 Then
        GUICtrlSetData($listviewitem[$currentsound], $repeats[$currentsound] & "|" & 0 & "|" & $sounds[$currentsound])
        GUICtrlSetBkColor($listviewitem[$currentsound], 0xFFFFFF)
        If $currentsound > 2 Then
            $currentsound -= 1
        Else
            $currentsound = UBound($sounds) - 1
        EndIf
        $currentrepeat = $repeats[$currentsound]
        GUICtrlSetBkColor($listviewitem[$currentsound], 0xFFFF00)
    Else
        $currentrepeat -= 1
    EndIf
    GUICtrlSetData($listviewitem[$currentsound], $repeats[$currentsound] & "|" & $currentrepeat & "|" & $sounds[$currentsound])
    _SoundPlay($sounds[$currentsound])
EndFunc

Func fastforward()
    GUICtrlSetData($playpause, "Play")
    If $playing = 3 Then
        $seekspeed *= 2
    Else
        $seekspeed = 2
        $playing = 3
    EndIf
EndFunc

Func fastbackward()
    GUICtrlSetData($playpause, "Play")
    If $playing = 4 Then
        $seekspeed *= 2
    Else
        $seekspeed = 2
        $playing = 4
    EndIf
EndFunc

Func close()
    Exit
EndFunc

@Admiral Alkex

Could you give me the code you used to create a menu when you right click on a listview item? And btw, the volume and speed change of EMP don't work for me.

Edit: Changed from listviewitem selection to highlight for current song and it changed some stuff pertinent to my question.

Edit2: Now the reason for which I am making this is working :). I made a temporary button to add a repeat to a song until I can get a menu with right click.

Edited by Hawkwing

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Share this post


Link to post
Share on other sites

I'm having a bit of trouble with the seeking, I want to be able to click the button once, and it goes 2x speed, again and it goes 4x, etc.

This is what I have, but it doesn't seem to do anything.

If TimerDiff($timer) > 1000 Then
    Local $hour, $min, $sec
    $temp = _SoundPos($sounds[$currentsound], 2) + $seekspeed * 1000
    _TicksToTime($temp, $hour, $min, $sec)
    _SoundSeek($sounds[$currentsound], $hour, $min, $sec)
    $timer = TimerInit()
EndIf

First of all, when you use the beta, please say so. I was on my way to post here and ask how god damn crazy you are since nothing worked when I noticed it work on the beta.... Anyway the reason it doesn't work is because you didn't read the remarks section for _SoundSeek() in the helpfile :)

-stripped-

@Admiral Alkex

Could you give me the code you used to create a menu when you right click on a listview item?

Sure, here is an example build by the actual EMP code. Please note that it's far from optimal, those GUICtrlGetHandle() could be moved to global variables to save some cpu-cycles etc...

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Include <GuiListView.au3>
#Include <GuiListBox.au3>

Opt("GUIOnEventMode", 1)

$GUI = GUICreate("Evolutionized Media Player v15", 640, 480, -1, 5)
GUISetState()

$ListView = GUICtrlCreateListView("Column 1|2|Column 3", 401, 38, 233, 347, BitOR($LVS_SHOWSELALWAYS, $LBS_NOINTEGRALHEIGHT, $LVS_NOSORTHEADER), BitOR($LVS_EX_INFOTIP, $LVS_EX_FULLROWSELECT, $LVS_EX_GRIDLINES, $LVS_EX_DOUBLEBUFFER, $LVS_EX_HEADERDRAGDROP))
GUICtrlSetTip(-1, "Right-click for menu")

$ListViewContext = GUICtrlCreateContextMenu(GUICtrlCreateDummy())
$Context1 = GUICtrlCreateMenuItem("Add media", $ListViewContext)
GUICtrlSetOnEvent(-1, "_CtrlEvents")
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

While 1
    Sleep(10)
WEnd

Func _CtrlEvents()
    Switch @GUI_CtrlId
        Case $Context1;, $Add
            MsgBox(0, "You pressed", "Add media")
    EndSwitch
EndFunc

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo, $MousePos[2], $hMenu = GUICtrlGetHandle($ListViewContext)
    $hWndListView = $ListView
    If Not IsHWnd($ListView) Then $hWndListView = GUICtrlGetHandle($ListView)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
        Case $hWndListView
            Switch $iCode
                Case $NM_RCLICK ;Right-click, taken somewhere from the forum
                    $MousePos = MouseGetPos()
                    TrackPopupMenu($hWnd, $hMenu, $MousePos[0], $MousePos[1])
                    Return 0
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Func TrackPopupMenu($hWnd, $hMenu, $x, $y)  ;Somewhere from the forum
    DllCall("user32.dll", "int", "TrackPopupMenuEx", "hwnd", $hMenu, "int", 0, "int", $x, "int", $y, "hwnd", $hWnd, "ptr", 0)
EndFunc   ;==>TrackPopupMenu

And btw, the volume and speed change of EMP don't work for me.

Edit: Changed from listviewitem selection to highlight for current song and it changed some stuff pertinent to my question.

Edit2: Now the reason for which I am making this is working :). I made a temporary button to add a repeat to a song until I can get a menu with right click.

The speed and volume functions seem to only work with some codecs. What extension where your file? What codec is it? What Operating System do you have?

I just tried running EMP v15 (on win7, autoit 3.3.0.0) and I can control sound and volume for mp3-files, try that.

Share this post


Link to post
Share on other sites

Now I feel kind of stupid for not reading more thoroughly. Everything works now :)

#include<guiconstants.au3>
#include<buttonconstants.au3>
#include<sound.au3>
#include<misc.au3>
#include<date.au3>

_Singleton("Auto Player")

#NoTrayIcon

Opt("guioneventmode", 1)

#Region GUI
$autoplayer = GUICreate("Auto Player", 218, 278)
GUISetOnEvent($GUI_EVENT_CLOSE, "close")
GUISetBkColor(0xFFFFFF)

$menufile = GUICtrlCreateMenu("File")
$menufileopen = GUICtrlCreateMenuItem("Open", $menufile)
GUICtrlSetOnEvent(-1, "open")
$menufileexit = GUICtrlCreateMenuItem("Exit", $menufile)
GUICtrlSetOnEvent(-1, "close")

$menuoptions = GUICtrlCreateMenu("Options")
$menuoptionsrepeat = GUICtrlCreateMenuItem("Repeat", $menuoptions)
GUICtrlSetOnEvent(-1, "repeat")

$playpause = GUICtrlCreateButton("Play", 75, 5, 32, 32, $BS_BITMAP)
GUICtrlSetOnEvent(-1, "playpause")
$stop = GUICtrlCreateButton("Stop", 110, 5, 32, 32, $BS_BITMAP)
GUICtrlSetOnEvent(-1, "stop")
$fb = GUICtrlCreateButton("FB", 40, 5, 32, 32, $BS_BITMAP)
GUICtrlSetOnEvent(-1, "fastbackward")
$ff = GUICtrlCreateButton("FF", 145, 5, 32, 32, $BS_BITMAP)
GUICtrlSetOnEvent(-1, "fastforward")
$previous = GUICtrlCreateButton("P", 5, 5, 32, 32, $BS_BITMAP)
GUICtrlSetOnEvent(-1, "previoustrack")
$next = GUICtrlCreateButton("N", 180, 5, 32, 32, $BS_BITMAP)
GUICtrlSetOnEvent(-1, "nexttrack")
$timedisplay = GUICtrlCreateLabel("00:00:00/00:00:00", 5, 40, 150, 20)

$listview = GUICtrlCreateListView("T|C|Song                                     ", 5, 65, 208, 190)

Dim $autoplayer_AccelTable[1][2] = [["{SPACE}", $playpause]]
GUISetAccelerators($autoplayer_AccelTable)
GUISetState()
#EndRegion GUI
#EndRegion GUI

;~ $playing = 0 - stopped, 1 - playing, 2 - paused, 3 - seeking forward, 4 - seeking backward
Global $playing, $currentsound, $repeat, $seekspeed, $currentrepeat, $listviewitem
Dim $sounds[1], $repeats[1], $soundopen[1]

$timer = TimerInit()
While 1
    If $playing = 1 Then
        GUICtrlSetData($timedisplay, _SoundPos($soundopen[$currentsound]) & "/" & _SoundLength($soundopen[$currentsound]))
        If _SoundPos($soundopen[$currentsound], 2) + 100 > _SoundLength($soundopen[$currentsound], 2) Then
            _SoundStop($soundopen[$currentsound])
            If $currentrepeat = $repeats[$currentsound] Then
                $currentrepeat = 1
                GUICtrlSetData($listviewitem[$currentsound][0], $repeats[$currentsound] & "|" & 0 & "|" & $sounds[$currentsound])
                GUICtrlSetBkColor($listviewitem[$currentsound][0], 0xFFFFFF)
                If $currentsound < UBound($sounds) - 1 Then
                    $currentsound += 1
                    _SoundPlay($soundopen[$currentsound])
                ElseIf $repeat = 1 Then
                    $currentsound = 2
                    _SoundPlay($soundopen[$currentsound])
                Else
                    $currentrepeat = $repeats[$currentsound]
                    stop()
                EndIf
                GUICtrlSetBkColor($listviewitem[$currentsound][0], 0xFFFF00)
            Else
                $currentrepeat += 1
                _SoundPlay($soundopen[$currentsound])
            EndIf
            GUICtrlSetData($listviewitem[$currentsound][0], $repeats[$currentsound] & "|" & $currentrepeat & "|" & $sounds[$currentsound])
        EndIf
    ElseIf $playing = 3 Then
        If TimerDiff($timer) > 1000 Then
            Local $hour, $min, $sec
            $temp = _SoundPos($soundopen[$currentsound], 2) + $seekspeed * 1000
            If $temp > _SoundLength($soundopen[$currentsound], 2) - 100 Then
                GUICtrlSetData($playpause, "Pause")
                $playing = 1
                nexttrack()
                ContinueLoop
            EndIf
            _TicksToTime($temp, $hour, $min, $sec)
            _SoundSeek($soundopen[$currentsound], $hour, $min, $sec)
            If GUICtrlRead($playpause) = "Pause" Then _SoundPlay($soundopen[$currentsound])
            GUICtrlSetData($timedisplay, _SoundPos($soundopen[$currentsound]) & "/" & _SoundLength($soundopen[$currentsound]))
            $timer = TimerInit()
        EndIf
    ElseIf $playing = 4 Then
        If TimerDiff($timer) > 1000 Then
            Local $hour, $min, $sec
            $temp = _SoundPos($soundopen[$currentsound], 2) - $seekspeed * 1000
            If $seekspeed * 1000 > _SoundPos($soundopen[$currentsound], 2) - 100 Then
                GUICtrlSetData($playpause, "Pause")
                $playing = 2
                stop()
                ContinueLoop
            EndIf
            _TicksToTime($temp, $hour, $min, $sec)
            _SoundSeek($soundopen[$currentsound], $hour, $min, $sec)
            If GUICtrlRead($playpause) = "Pause" Then _SoundPlay($soundopen[$currentsound])
            GUICtrlSetData($timedisplay, _SoundPos($soundopen[$currentsound]) & "/" & _SoundLength($soundopen[$currentsound]))
            $timer = TimerInit()
        EndIf
    EndIf
WEnd


Func open()
    $path = FileOpenDialog("Open Files", "D:\Audio", "Audio (*.mp3; *.wav)", 7)
    If $path = "" Then Return
    If StringInStr($path, "|") Then
        $sounds = StringSplit($path, "|")
        Dim $soundopen[UBound($sounds)]
        For $i = 2 To UBound($sounds) - 1
            $soundopen[$i] = _SoundOpen($sounds[1] & "\" & $sounds[$i])
        Next
    Else
        Dim $sounds[3]
        Dim $soundopen[UBound($sounds)]
        $sounds[2] = $path
        $soundopen[2] = _SoundOpen($sounds[2])
    EndIf
    Global $listviewitem[UBound($sounds)][4], $repeats[UBound($sounds)]
    For $i = 2 To UBound($sounds) - 1
        $listviewitem[$i][0] = GUICtrlCreateListViewItem(1 & "|" & 0 & "|" & $sounds[$i], $listview)
        $listviewitem[$i][1] = GUICtrlCreateContextMenu($listviewitem[$i][0])
        $listviewitem[$i][2] = GUICtrlCreateMenuItem("Add Repeat", $listviewitem[$i][1])
        GUICtrlSetOnEvent(-1, "addrepeat")
        $listviewitem[$i][3] = GUICtrlCreateMenuItem("Remove Repeat", $listviewitem[$i][1])
        GUICtrlSetOnEvent(-1, "removerepeat")
        $repeats[$i] = 1
    Next
    $currentsound = 2
    $currentrepeat = 1
    GUICtrlSetData($listviewitem[$currentsound][0], $repeats[$currentsound] & "|" & $currentrepeat & "|" & $sounds[$currentsound])
    GUICtrlSetBkColor($listviewitem[$currentsound][0], 0xFFFF00)
    _SoundPlay($soundopen[2])
    $playing = 1
    GUICtrlSetData($playpause, "Pause")
EndFunc

Func playpause()
    If $playing = 1 Then
        _SoundPause($soundopen[$currentsound])
        $playing = 2
        GUICtrlSetData($playpause, "Play")
    ElseIf $playing = 2 Then
        _SoundResume($soundopen[$currentsound])
        GUICtrlSetData($playpause, "Pause")
        $playing = 1
    ElseIf $playing = 0 Then
        _SoundPlay($soundopen[$currentsound])
        GUICtrlSetData($playpause, "Pause")
        $playing = 1
    ElseIf $playing = 3 Or $playing = 4 Then
        If GUICtrlRead($playpause) = "Play" Then
            _SoundPlay($soundopen[$currentsound])
            GUICtrlSetData($playpause, "Pause")
        EndIf
        $playing = 1
    EndIf
EndFunc

Func stop()
    $playing = 0
    _SoundStop($soundopen[$currentsound])
    GUICtrlSetData($playpause, "Play")
    GUICtrlSetData($timedisplay, "00:00:00/" & _SoundLength($sounds[$currentsound]))
EndFunc

Func repeat()
    If $repeat = 0 Then
        $repeat = 1
        GUICtrlSetState($menuoptionsrepeat, $GUI_CHECKED)
    ElseIf $repeat = 1 Then
        $repeat = 0
        GUICtrlSetState($menuoptionsrepeat, $GUI_UNCHECKED)
    EndIf
EndFunc

Func nexttrack()
    _SoundStop($soundopen[$currentsound])
    If $currentrepeat = $repeats[$currentsound] Then
        $currentrepeat = 1
        GUICtrlSetData($listviewitem[$currentsound][0], $repeats[$currentsound] & "|" & 0 & "|" & $sounds[$currentsound])
        GUICtrlSetBkColor($listviewitem[$currentsound][0], 0xFFFFFF)
        If $currentsound < UBound($sounds) - 1 Then
            $currentsound += 1
        Else
            $currentsound = 2
        EndIf
        GUICtrlSetBkColor($listviewitem[$currentsound][0], 0xFFFF00)
    Else
        $currentrepeat += 1
    EndIf
    GUICtrlSetData($listviewitem[$currentsound][0], $repeats[$currentsound] & "|" & $currentrepeat & "|" & $sounds[$currentsound])
    _SoundPlay($soundopen[$currentsound])
EndFunc

Func previoustrack()
    _SoundStop($soundopen[$currentsound])
    If $currentrepeat = 1 Then
        GUICtrlSetData($listviewitem[$currentsound][0], $repeats[$currentsound] & "|" & 0 & "|" & $sounds[$currentsound])
        GUICtrlSetBkColor($listviewitem[$currentsound][0], 0xFFFFFF)
        If $currentsound > 2 Then
            $currentsound -= 1
        Else
            $currentsound = UBound($sounds) - 1
        EndIf
        $currentrepeat = $repeats[$currentsound]
        GUICtrlSetBkColor($listviewitem[$currentsound][0], 0xFFFF00)
    Else
        $currentrepeat -= 1
    EndIf
    GUICtrlSetData($listviewitem[$currentsound][0], $repeats[$currentsound] & "|" & $currentrepeat & "|" & $sounds[$currentsound])
    _SoundPlay($soundopen[$currentsound])
EndFunc

Func fastforward()
    If $playing = 3 Then
        $seekspeed *= 2
    Else
        $seekspeed = 2
        $playing = 3
    EndIf
EndFunc

Func fastbackward()
    If $playing = 4 Then
        $seekspeed *= 2
    Else
        $seekspeed = 2
        $playing = 4
    EndIf
EndFunc

Func addrepeat()
    For $i = 2 To UBound($listviewitem) - 1
        If @GUI_CtrlId = $listviewitem[$i][2] Then
            $temp = 0
            If $currentsound = $i Then $temp = $currentrepeat
            $repeats[$i] += 1
            GUICtrlSetData($listviewitem[$i][0], $repeats[$i] & "|" & $temp & "|" & $sounds[$i])
            ExitLoop
        EndIf
    Next
EndFunc

Func removerepeat()
    For $i = 2 To UBound($listviewitem) - 1
        If @GUI_CtrlId = $listviewitem[$i][3] Then
            $temp = 0
            If $currentsound = $i Then $temp = $currentrepeat
            If $repeats[$i] > 1 Then $repeats[$i] -= 1
            GUICtrlSetData($listviewitem[$i][0], $repeats[$i] & "|" & $temp & "|" & $sounds[$i])
            ExitLoop
        EndIf
    Next
EndFunc

Func close()
    Exit
EndFunc

The only bad thing I've come across so far is that if I've right clicked on a song, it won't continue to the next one until I click a button or close the menu.

The speed and volume functions seem to only work with some codecs. What extension where your file? What codec is it? What Operating System do you have?

I just tried running EMP v15 (on win7, autoit 3.3.0.0) and I can control sound and volume for mp3-files, try that.

I was using a .wav, but when I tested it with an .mp3 it worked fine.

The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

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