Jump to content

Toggle Play and pause in audio player


ajit
 Share

Recommended Posts

#Include <GUIConstantsEx.Au3>
#Include <WindowsConstants.Au3>
#Include <Misc.Au3>
#Include <Sound.Au3>
#Include <File.Au3>
#Include <String.Au3>
#Include <GUIListBox.Au3>
Opt ('GUIOnEventMode','1')
Opt ('TrayMenuMode','1')
Opt ('TrayOnEventMode','1') 

Local $playstatus = 0, $Edit
HotKeySet("{F6}", "status")
;HotKeySet("{F6}", "msg")
HotKeySet("{F11}", "rewind")



$SOptions = TrayCreateMenu ('Song Options')
$TPlay_S = TrayCreateItem ('Play Song', $SOptions)
TrayItemSetOnEvent ($TPlay_S, '_Play')
$TStop_S = TrayCreateItem ('Stop Song', $SOptions)
;TrayItemSetOnEvent ($TStop_S, '_End')
$TPause_S = TrayCreateItem ('Pause Song', $SOptions)
TrayItemSetOnEvent ($TPause_S, '_Pause')
$TPAll_S = TrayCreateItem ('Play All', $SOptions)
;TrayItemSetOnEvent ($TPAll_S, '_Play_All')
$TLoop_S = TrayCreateItem ('Loop Song', $SOptions) 
;TrayItemSetOnEvent ($TLoop_S, '_Loop')
$POptions = TrayCreateMenu ('Program Options')
$PHide = TrayCreateItem ('Hide / Show', $POptions)
TrayItemSetOnEvent ($PHide, '_HideShow')
$PExit = TrayCreateItem ('Exit', $POptions)
TrayItemSetOnEvent ($PExit, '_Exit')

Global $S_Pause = False, $Open = '-1', $Toggle = False, $S_Play = False, $Time_S = '-1', $P_All = False, $L = 0, $Pos, $Length, $Loop = False, $1 = False
Global $Toggle = False, $Last = '-1' 

$GUI = GUICreate ('S.M.P. v1.0 - By : John O.',@DesktopWidth,'70','-1','0','-1','264')
;GUISetBkColor ('0x000000')
GUISetOnEvent ($GUI_EVENT_CLOSE, '_Exit')
GUICtrlCreateGroup ('','5','0','289','32')
$Slider = GUICtrlCreateSlider ('8','9','283','20', BitOr ('0x0008','0x0010'))
GUICtrlSetOnEvent ($Slider, '_Seek')
GUICtrlSetBkColor ($Slider, '0')
GUICtrlCreateGroup ('','5','32','180','33')
;$List = GUICtrlCreateList ('- No Songs -','8','41','174','200', BitOr ('0x00100000','0x1000','0xA00003'))
;GUICtrlSetFont ($List, '9','600')
;GUICtrlSetColor ($List, '0x0000FF')
GUICtrlCreateGroup ('','191','32','740','33')


$Add = GUICtrlCreateButton ('Add Song','194','41','97','20','32896')
GUICtrlSetOnEvent ($Add, '_Add_GUI')
GUICtrlSetBkColor ($Add, '0x000000')
GUICtrlSetColor ($Add, '0xFFFFFF')
GUICtrlSetFont ($Add, '9','600')
$Delete = GUICtrlCreateButton ('Delete Song','300','41','97','20','32896')
;GUICtrlSetOnEvent ($Delete, '_Delete')
GUICtrlSetBkColor ($Delete, '0x000000')
GUICtrlSetColor ($Delete, '0xFFFFFF')
GUICtrlSetFont ($Delete, '9','600')
$Play = GUICtrlCreateButton ('Play Song','406','41','97','20','32896')
GUICtrlSetOnEvent ($Play, '_Play')
GUICtrlSetBkColor ($Play, '0x000000')
GUICtrlSetColor ($Play, '0xFFFFFF')
GUICtrlSetFont ($Play, '9','600')
$Stop = GUICtrlCreateButton ('Stop Song','512','41','97','20','32896')
GUICtrlSetOnEvent ($Stop, '_End')
GUICtrlSetBkColor ($Stop, '0x000000')
GUICtrlSetColor ($Stop, '0xFFFFFF')
GUICtrlSetFont ($Stop, '9','600')
$Pause = GUICtrlCreateButton ('Pause Song','618','41','97','20','32896')
GUICtrlSetOnEvent ($Pause, '_Pause')
GUICtrlSetBkColor ($Pause, '0x000000')
GUICtrlSetColor ($Pause, '0xFFFFFF')
GUICtrlSetFont ($Pause, '9','600')
$Play_All = GUICtrlCreateButton ('Play All','724','41','97','20','32896')
;GUICtrlSetOnEvent ($Play_All, '_Play_All')
GUICtrlSetBkColor ($Play_All, '0x000000')
GUICtrlSetColor ($Play_All, '0xFFFFFF')
GUICtrlSetFont ($Play_All, '9','600')
$Loop_Song = GUICtrlCreateButton ('Rewind Song','830','41','97','20','32896')
GUICtrlSetOnEvent ($Loop_Song, 'rewind')
GUICtrlSetBkColor ($Loop_Song, '0x000000')
GUICtrlSetColor ($Loop_Song, '0xFFFFFF')
GUICtrlSetFont ($Loop_Song, '9','600')
$L_Pos = GUICtrlCreateLabel ('00:00:00','940','10','100','20')
GUICtrlSetColor ('-1','0xFF0000')
GUICtrlSetBkColor ('-1', $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetFont ('-1','9','600','','Arial')
GUICtrlCreateLabel ('___________','940','15','100','13')
GUICtrlSetColor ('-1','0xFFFFFF')
GUICtrlSetBkColor ('-1', $GUI_BKCOLOR_TRANSPARENT)
$L_Length = GUICtrlCreateLabel ('00:00:00','940','33','100','20')
GUICtrlSetColor ('-1','0xFF0000')
GUICtrlSetBkColor ('-1', $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetFont ('-1','9','600','','Arial')
GUISetState (@SW_SHOW, $GUI)
WinSetOnTop ($GUI, '','1')
;_List ()
GUICtrlCreateLabel("Audio File = C:\Mysound.wav", 400, 10, 250)
GUICtrlSetFont ('-1','9','600','','Arial')
GUICtrlSetColor ('-1','0xFF0000')

While '1'
Sleep ('100') 



If FileExists("C:\START.TXT") Then _play()
If Not FileExists("C:\START.TXT") Then _pause()




If $Toggle <> False Then 
$Pos = _SoundPos ($Open, '2')
$Length = _SoundLength ($Open, '2')
_Update (_SoundPos ($Open), _SoundLength ($Open))
;If $Pos >= $Length Then _End ()
$X = $Pos / $Length * '100'
If _Check () == '0' Then GUICtrlSetData ($Slider, $X)
EndIf 

WEnd

Func _Play ()
If $S_Play = True And $S_Pause = False Then Return @Error 
If $P_All = True Then 
$Song = FileReadLine ('List.ini', $L)
If $Song = '-1' Then Return @Error
$Open = _SoundOpen ($Song)
_SoundPlay ($Open)
$Toggle = True 
$S_Play = True 
Return '1'
EndIf 
If $S_Pause = True Then 
$S_Pause = False
;_SoundResume ($Open)
$pause_pos = _SoundPos ($Open)
;consolewrite($pause_pos & @CRLF) 
$hours = Stringtrimright($pause_pos, 6) 
$minutes = Stringtrimright(StringTrimleft($pause_pos, 3), 3) 
$seconds = StringTrimleft($pause_pos, 6)
;consolewrite($seconds & @CRLF)
If $hours = 0 And $minutes  = 0 And  $seconds <= 3 Then _SoundSeek ($Open, 00, 00, 00)
If $hours + $minutes  + $seconds > 3 Then _SoundSeek ($Open, $hours, $minutes  , ($seconds - 3))
;consolewrite("a" & $hours & ":" & $minutes  & ":" & $seconds) 
;_SoundSeek ($Open, $hours, $minutes  , ($seconds - 5))
_SoundPlay ($Open)
Else 




$Song = "C:\Mysound.wav"


;$Song = "C:\Documents and Settings\user\Desktop\Dragon Trascription Folder\Dragon Text\Wong Text\Z0000000.wav" ; _GetCurrentSong ()
If $Song = '-1' Then Return @Error 
$Open = _SoundOpen ($Song)
_SoundPlay ($Open)
$Toggle = True 
$S_Play = True 
EndIf 
EndFunc

Func _Convert ($Mili_Sec)
Local $Hour = '0', $Min = '0', $Sec = '0', $R['4']
$Sec = $Mili_Sec / '1000'
If $Sec > '60' Then 
Do 
$Sec = $Sec - '60'
$Min = $Min + '1'
Until $Sec < '60'
EndIf 
If $Min > '60' Then 
Do 
$Min = $Min - '60'
$Hour = $Hour + '1'
Until $Min < '60'
EndIf 
Dim $R 
$R['1'] = $Hour
$R['2'] = $Min
$R['3'] = $Sec
Return $R
EndFunc

Func _Update ($S_Pos, $S_Length)
If $Last <> '-1' And TimerDiff ($Last) < '800' Then Return @Error 
GUICtrlSetData ($L_Pos, $S_Pos)
If GUICtrlRead ($L_Length) <> $S_Length Then GUICtrlSetData ($L_Length, $S_Length)
$Last = TimerInit ()
EndFunc

Func _Check ()
Local $Aa = '0'
If _IsPressed ('01') Or _IsPressed ('25') Or _IsPressed ('27') Then $Aa = '1'
If ControlGetFocus ($GUI) = 'msctls_trackbar321' And $Aa = '1' Then $Time_S = TimerInit ()
If $Time_S <> '-1' And TimerDiff ($Time_S) >= '1000' Then 
$Time_S = '-1'
ElseIf $Time_S <> '-1' Then  
Return '1'
EndIf 
If ControlGetFocus ($GUI) = 'msctls_trackbar321' And $Aa = '1' Then
$Time_S = TimerInit ()  
Return '1'
Else 
Return '0'
EndIf 
EndFunc

Func _Add_GUI ()
WinSetOnTop ($GUI, '','0')
Global $GUI_Add = GUICreate ('Drag-&-Drop 2 Add Files','200','100','-1','-1','-1', BitOr ('128','0x00000010'))
GUISetBkColor ('0x000000')
GUISetOnEvent ($GUI_EVENT_CLOSE, '_Exit_Add')
GUISetOnEvent ($GUI_EVENT_DROPPED, '_Add')
Global $Edit = GUICtrlCreateEdit ('','0','0','200','100','3')
GUICtrlSetState ('-1', BitOr ($GUI_DISABLE, $GUI_DROPACCEPTED))
GUICtrlSetBkColor ('-1','0x000000')
GUICtrlSetColor ('-1','0x000000')
GUISetState (@SW_SHOW, $GUI_Add)
WinSetOnTop ($GUI_Add, '','1')
EndFunc

Func _Exit ()
Exit
EndFunc


Func _Add ()
GUICtrlSetData ($Edit, '')
FileWriteLine ('List.ini', @GUI_DragFile)
;_List ()
EndFunc


Func _FileGetName ($iFile)
$Char = StringSplit (_FileGetType ($iFile), '')
$Char = $Char['0']
Return StringTrimRight ($iFile, $Char)
EndFunc

Func _FileGetType ($iFile)
$String = _StringReverse ($iFile)
$String = StringSplit ($String, '.')
$String = '.' & _StringReverse ($String['1'])
Return $String
EndFunc


Func msg()
    MsgBox(0, "", "")
    EndFunc

Func _Pause ()
    
If $Toggle = False Then Return @Error 
If $S_Play = False Then Return @Error 
If $S_Pause = True Then Return @Error 



$S_Pause = True 
;$pause_pos = _SoundPos ($Open)
;consolewrite($pause_pos & @CRLF)
;$seconds = Consolewrite(StringTrimleft($pause_pos, 6) & @CRLF)
;$minutes = Consolewrite(Stringtrimright(StringTrimleft($pause_pos, 3), 3) & @CRLF)
;$hours = Consolewrite(Stringtrimright($pause_pos, 6) & @CRLF)
;consolewrite("**" & 0 & $hours & ":" & 0 & $minutes & ":" & 0 & $seconds )
_SoundPause ($Open)
;_SoundStop ($Open)
;_SoundSeek ($Open, 0 & $hours, 0 & $minutes , 0 & $seconds - 03)
;_SoundResume($Open)
;_SoundPlay ($Open)
;_SoundPause ($Open)
IniWrite("C:\myfile.ini", "section2", "status", "pause")    
EndFunc 

Func _Seek ()
If $Toggle = False Then Return @Error 
If $S_Play = False Then Return @Error 
_SoundStop ($Open)
$S = GUICtrlRead ($Slider)
;If $S = '100' Then _End ()
$P = (_SoundLength ($Open, '2') / '100') * $S 
$P = _Convert ($P)
_SoundSeek ($Open, Round ($P['1'], '0'), Round ($P['2'], '0'), Round ($P['3'], '0'))
_SoundPlay ($Open)
EndFunc

Func _HideShow ()
If $Toggle = False Then 
$Toggle = True 
WinSetState ($GUI, '', @SW_HIDE)
Else 
$Toggle =False
WinSetState ($GUI, '', @SW_SHOW)
EndIf 
EndFunc

Local $GUI_Add
Func _Exit_Add ()
WinSetOnTop ($GUI_Add, '','0')
GUIDelete ($GUI_Add)
WinSetOnTop ($GUI, '','1')
EndFunc


Func status()
    
If $playstatus = 0 and IniRead("C:\myfile.ini", "section2", "status", "")   = "pause" Then 
;_Seek ()
_Play ()
$playstatus = 1 
Elseif $playstatus = 1  and IniRead("C:\myfile.ini", "section2", "status", "")  = "play" Then 
_Pause ()
$playstatus = 0
EndIf
EndFunc


Func rewind()
$pause_pos = _SoundPos ($Open)
;consolewrite($pause_pos & @CRLF) 
$hours = Stringtrimright($pause_pos, 6) 
$minutes = Stringtrimright(StringTrimleft($pause_pos, 3), 3) 
$seconds = StringTrimleft($pause_pos, 6)
;consolewrite($seconds & @CRLF)
;If $hours + $minutes  + $seconds <= 5 Then _SoundSeek ($Open, 00, 00, 00)
;If $hours + $minutes  + $seconds > 5 Then _SoundSeek ($Open, $hours, $minutes  , ($seconds - 5))
;consolewrite("Rewind" & $hours & ":" & $minutes  & ":" & $seconds & @CRLF)
_SoundStop ($Open)
_SoundSeek ($Open, $hours, $minutes  , ($seconds - 5))
_SoundPlay ($Open)
EndFunc


Func _End()
_SoundStop ($Open)
$S_Pause = True 
EndFunc

I have a audio player which plays when there is a file "C:\START.TXT" file in C drive.

The file appears and dissapears. I want to toggle the player from play() to pause() during this transition.

When "C:\START.TXT" Exits then play() and next time when "C:\START.TXT" Exits to Pause() but I could not find a way to do it.

I have attached the player. au3 as well as a GUI to test it i.e. to create a file "C:\START.TXT" momentarily.

The player needs C:\Mysound.wav file to run. I have uploaded the files.

I know it is a lot of trouble but I am really stuck.

Can someone help me.

Player+test.zip

Link to comment
Share on other sites

  • Moderators

ajit,

When "C:\START.TXT" Exits then play() and next time when "C:\START.TXT" Exits to Pause()

Just to check I understand:

You want the player to toggle each time the file is deleted? Or do you want the player to pause when the file is not present?

Final question - do you want to use this particular player or can your MySound.wav be played in a separate script (it would be much simpler!).

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Hi Melba23,

Thanks for your interest in my problem.

I want the player to toggle each time the file is created that is to continue playing till the file "C:\START.TXT" exists the next time after it gets deleted.

Cycle 1

file exits = play

file deleted = continue playing

Cycle 2

file exits = pause

file deleted = continue pause

Cycle 3

file exits = play

file deleted = continue playing

These are three cycles, like creating the file ("C:\START.TXT") three times which would start playing, then next cycle pause, and then again play.

For your second question, I think the trigger for transition should be when file exits.

As for your final questions, I do not have any other player with GUIOnEventMode and they work, I believe, better than NON-GUIOnEventMode players, which are sometimes unnresposive while playing. I would not mind changing my player for another good one.

And just for info I want to use the player for transcription and the "C:\START.TXT" is created when I press a footpedal switch (Com1).

WIth my limited knowledge of programming I usually use scripts that I find in forums after modifying them.

Thanks again for your interest in helping me.

Regards

Ajit

Link to comment
Share on other sites

  • Moderators

ajit,

Apologies for the earlier confusion, but you are using "exits" (= "departs" or "is no longer there") when you mean "exists" (= "is there") - which is why I was unsure exactly what you wanted! The cycle explanation was perfectly clear. :D

I think this should do what you want:

#include <GUIConstantsEx.Au3>
#include <WindowsConstants.Au3>
#include <Misc.Au3>
#include <Sound.Au3>
#include <File.Au3>
#include <String.Au3>
#include <GUIListBox.Au3>
Opt('GUIOnEventMode', '1')
Opt('TrayMenuMode', '1')
Opt('TrayOnEventMode', '1')

Local $playstatus = 0, $Edit
HotKeySet("{F6}", "status")
;HotKeySet("{F6}", "msg")
HotKeySet("{F11}", "rewind")

$SOptions = TrayCreateMenu('Song Options')
$TPlay_S = TrayCreateItem('Play Song', $SOptions)
TrayItemSetOnEvent($TPlay_S, '_Play')
$TStop_S = TrayCreateItem('Stop Song', $SOptions)
;TrayItemSetOnEvent ($TStop_S, '_End')
$TPause_S = TrayCreateItem('Pause Song', $SOptions)
TrayItemSetOnEvent($TPause_S, '_Pause')
$TPAll_S = TrayCreateItem('Play All', $SOptions)
;TrayItemSetOnEvent ($TPAll_S, '_Play_All')
$TLoop_S = TrayCreateItem('Loop Song', $SOptions)
;TrayItemSetOnEvent ($TLoop_S, '_Loop')
$POptions = TrayCreateMenu('Program Options')
$PHide = TrayCreateItem('Hide / Show', $POptions)
TrayItemSetOnEvent($PHide, '_HideShow')
$PExit = TrayCreateItem('Exit', $POptions)
TrayItemSetOnEvent($PExit, '_Exit')

Global $S_Pause = False, $Open = '-1', $Toggle = False, $S_Play = False, $Time_S = '-1', $P_All = False, $L = 0, $Pos, $Length, $Loop = False, $1 = False
Global $Toggle = False, $Last = '-1'
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Global $sFile = "C:\START.TXT"
Global $fCycle = True
Global $fState = False
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$GUI = GUICreate('S.M.P. v1.0 - By : John O.', @DesktopWidth, '70', '-1', '0', '-1', '264')
;GUISetBkColor ('0x000000')
GUISetOnEvent($GUI_EVENT_CLOSE, '_Exit')
GUICtrlCreateGroup('', '5', '0', '289', '32')
$Slider = GUICtrlCreateSlider('8', '9', '283', '20', BitOR('0x0008', '0x0010'))
GUICtrlSetOnEvent($Slider, '_Seek')
GUICtrlSetBkColor($Slider, '0')
GUICtrlCreateGroup('', '5', '32', '180', '33')
;$List = GUICtrlCreateList ('- No Songs -','8','41','174','200', BitOr ('0x00100000','0x1000','0xA00003'))
;GUICtrlSetFont ($List, '9','600')
;GUICtrlSetColor ($List, '0x0000FF')
GUICtrlCreateGroup('', '191', '32', '740', '33')

$Add = GUICtrlCreateButton('Add Song', '194', '41', '97', '20', '32896')
GUICtrlSetOnEvent($Add, '_Add_GUI')
GUICtrlSetBkColor($Add, '0x000000')
GUICtrlSetColor($Add, '0xFFFFFF')
GUICtrlSetFont($Add, '9', '600')
$Delete = GUICtrlCreateButton('Delete Song', '300', '41', '97', '20', '32896')
;GUICtrlSetOnEvent ($Delete, '_Delete')
GUICtrlSetBkColor($Delete, '0x000000')
GUICtrlSetColor($Delete, '0xFFFFFF')
GUICtrlSetFont($Delete, '9', '600')
$Play = GUICtrlCreateButton('Play Song', '406', '41', '97', '20', '32896')
GUICtrlSetOnEvent($Play, '_Play')
GUICtrlSetBkColor($Play, '0x000000')
GUICtrlSetColor($Play, '0xFFFFFF')
GUICtrlSetFont($Play, '9', '600')
$Stop = GUICtrlCreateButton('Stop Song', '512', '41', '97', '20', '32896')
GUICtrlSetOnEvent($Stop, '_End')
GUICtrlSetBkColor($Stop, '0x000000')
GUICtrlSetColor($Stop, '0xFFFFFF')
GUICtrlSetFont($Stop, '9', '600')
$Pause = GUICtrlCreateButton('Pause Song', '618', '41', '97', '20', '32896')
GUICtrlSetOnEvent($Pause, '_Pause')
GUICtrlSetBkColor($Pause, '0x000000')
GUICtrlSetColor($Pause, '0xFFFFFF')
GUICtrlSetFont($Pause, '9', '600')
$Play_All = GUICtrlCreateButton('Play All', '724', '41', '97', '20', '32896')
;GUICtrlSetOnEvent ($Play_All, '_Play_All')
GUICtrlSetBkColor($Play_All, '0x000000')
GUICtrlSetColor($Play_All, '0xFFFFFF')
GUICtrlSetFont($Play_All, '9', '600')
$Loop_Song = GUICtrlCreateButton('Rewind Song', '830', '41', '97', '20', '32896')
GUICtrlSetOnEvent($Loop_Song, 'rewind')
GUICtrlSetBkColor($Loop_Song, '0x000000')
GUICtrlSetColor($Loop_Song, '0xFFFFFF')
GUICtrlSetFont($Loop_Song, '9', '600')
$L_Pos = GUICtrlCreateLabel('00:00:00', '940', '10', '100', '20')
GUICtrlSetColor('-1', '0xFF0000')
GUICtrlSetBkColor('-1', $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetFont('-1', '9', '600', '', 'Arial')
GUICtrlCreateLabel('___________', '940', '15', '100', '13')
GUICtrlSetColor('-1', '0xFFFFFF')
GUICtrlSetBkColor('-1', $GUI_BKCOLOR_TRANSPARENT)
$L_Length = GUICtrlCreateLabel('00:00:00', '940', '33', '100', '20')
GUICtrlSetColor('-1', '0xFF0000')
GUICtrlSetBkColor('-1', $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetFont('-1', '9', '600', '', 'Arial')
GUISetState(@SW_SHOW, $GUI)
WinSetOnTop($GUI, '', '1')
;_List ()
GUICtrlCreateLabel("Audio File = C:\Mysound.wav", 400, 10, 250)
GUICtrlSetFont('-1', '9', '600', '', 'Arial')
GUICtrlSetColor('-1', '0xFF0000')
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
If FileExists($sFile) Then
    _Play()
    $fState = True
Else
    _Play()
    _Pause()
EndIf
; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
While 1
    ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    If FileExists($sFile) = 1 Then
        ; Has it just been created
        If $fState = False Then
            ; Yes, it exists again - so change state
            $fState = True
            ; and check cycle state
            If $fCycle = True Then
                ; We should now play
                _Play()
            Else
                ; We should now stop
                _Pause()
            EndIf
        EndIf
        ; System settling time
        Sleep(100)
    ElseIf FileExists($sFile) = 0 Then
        ; Has it just been deleted
        If $fState = True Then
            ; Yes, it was deleted - so change state
            $fState = False
            ; And toggle cycle state
            $fCycle = Not $fCycle
        EndIf
        ; System settling time
        Sleep(100)
    EndIf
    ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    If $Toggle <> False Then
        $Pos = _SoundPos($Open, '2')
        $Length = _SoundLength($Open, '2')
        _Update(_SoundPos($Open), _SoundLength($Open))
        ;If $Pos >= $Length Then _End ()
        $X = $Pos / $Length * '100'
        If _Check() == '0' Then GUICtrlSetData($Slider, $X)
    EndIf

WEnd

Func _Play()
    If $S_Play = True And $S_Pause = False Then Return @error
    If $P_All = True Then
        $Song = FileReadLine('List.ini', $L)
        If $Song = '-1' Then Return @error
        $Open = _SoundOpen($Song)
        _SoundPlay($Open)
        $Toggle = True
        $S_Play = True
        Return '1'
    EndIf
    If $S_Pause = True Then
        $S_Pause = False
        ;_SoundResume ($Open)
        $pause_pos = _SoundPos($Open)
        ;consolewrite($pause_pos & @CRLF)
        $hours = StringTrimRight($pause_pos, 6)
        $minutes = StringTrimRight(StringTrimLeft($pause_pos, 3), 3)
        $seconds = StringTrimLeft($pause_pos, 6)
        ;consolewrite($seconds & @CRLF)
        If $hours = 0 And $minutes = 0 And $seconds <= 3 Then _SoundSeek($Open, 00, 00, 00)
        If $hours + $minutes + $seconds > 3 Then _SoundSeek($Open, $hours, $minutes, ($seconds - 3))
        ;consolewrite("a" & $hours & ":" & $minutes  & ":" & $seconds)
        ;_SoundSeek ($Open, $hours, $minutes  , ($seconds - 5))
        _SoundPlay($Open)
    Else

        $Song = "C:\Mysound.wav"

        ;$Song = "C:\Documents and Settings\user\Desktop\Dragon Trascription Folder\Dragon Text\Wong Text\Z0000000.wav" ; _GetCurrentSong ()
        If $Song = '-1' Then Return @error
        $Open = _SoundOpen($Song)
        _SoundPlay($Open)
        $Toggle = True
        $S_Play = True
    EndIf
EndFunc   ;==>_Play

Func _Convert($Mili_Sec)
    Local $Hour = '0', $Min = '0', $Sec = '0', $R['4']
    $Sec = $Mili_Sec / '1000'
    If $Sec > '60' Then
        Do
            $Sec = $Sec - '60'
            $Min = $Min + '1'
        Until $Sec < '60'
    EndIf
    If $Min > '60' Then
        Do
            $Min = $Min - '60'
            $Hour = $Hour + '1'
        Until $Min < '60'
    EndIf
    Dim $R
    $R['1'] = $Hour
    $R['2'] = $Min
    $R['3'] = $Sec
    Return $R
EndFunc   ;==>_Convert

Func _Update($S_Pos, $S_Length)
    If $Last <> '-1' And TimerDiff($Last) < '800' Then Return @error
    GUICtrlSetData($L_Pos, $S_Pos)
    If GUICtrlRead($L_Length) <> $S_Length Then GUICtrlSetData($L_Length, $S_Length)
    $Last = TimerInit()
EndFunc   ;==>_Update

Func _Check()
    Local $Aa = '0'
    If _IsPressed('01') Or _IsPressed('25') Or _IsPressed('27') Then $Aa = '1'
    If ControlGetFocus($GUI) = 'msctls_trackbar321' And $Aa = '1' Then $Time_S = TimerInit()
    If $Time_S <> '-1' And TimerDiff($Time_S) >= '1000' Then
        $Time_S = '-1'
    ElseIf $Time_S <> '-1' Then
        Return '1'
    EndIf
    If ControlGetFocus($GUI) = 'msctls_trackbar321' And $Aa = '1' Then
        $Time_S = TimerInit()
        Return '1'
    Else
        Return '0'
    EndIf
EndFunc   ;==>_Check

Func _Add_GUI()
    WinSetOnTop($GUI, '', '0')
    Global $GUI_Add = GUICreate('Drag-&-Drop 2 Add Files', '200', '100', '-1', '-1', '-1', BitOR('128', '0x00000010'))
    GUISetBkColor('0x000000')
    GUISetOnEvent($GUI_EVENT_CLOSE, '_Exit_Add')
    GUISetOnEvent($GUI_EVENT_DROPPED, '_Add')
    Global $Edit = GUICtrlCreateEdit('', '0', '0', '200', '100', '3')
    GUICtrlSetState('-1', BitOR($GUI_DISABLE, $GUI_DROPACCEPTED))
    GUICtrlSetBkColor('-1', '0x000000')
    GUICtrlSetColor('-1', '0x000000')
    GUISetState(@SW_SHOW, $GUI_Add)
    WinSetOnTop($GUI_Add, '', '1')
EndFunc   ;==>_Add_GUI

Func _Exit()
    Exit
EndFunc   ;==>_Exit

Func _Add()
    GUICtrlSetData($Edit, '')
    FileWriteLine('List.ini', @GUI_DragFile)
    ;_List ()
EndFunc   ;==>_Add

Func _FileGetName($iFile)
    $Char = StringSplit(_FileGetType($iFile), '')
    $Char = $Char['0']
    Return StringTrimRight($iFile, $Char)
EndFunc   ;==>_FileGetName

Func _FileGetType($iFile)
    $String = _StringReverse($iFile)
    $String = StringSplit($String, '.')
    $String = '.' & _StringReverse($String['1'])
    Return $String
EndFunc   ;==>_FileGetType

Func msg()
    MsgBox(0, "", "")
EndFunc   ;==>msg

Func _Pause()

    If $Toggle = False Then Return @error
    If $S_Play = False Then Return @error
    If $S_Pause = True Then Return @error

    $S_Pause = True
    ;$pause_pos = _SoundPos ($Open)
    ;consolewrite($pause_pos & @CRLF)
    ;$seconds = Consolewrite(StringTrimleft($pause_pos, 6) & @CRLF)
    ;$minutes = Consolewrite(Stringtrimright(StringTrimleft($pause_pos, 3), 3) & @CRLF)
    ;$hours = Consolewrite(Stringtrimright($pause_pos, 6) & @CRLF)
    ;consolewrite("**" & 0 & $hours & ":" & 0 & $minutes & ":" & 0 & $seconds )
    _SoundPause($Open)
    ;_SoundStop ($Open)
    ;_SoundSeek ($Open, 0 & $hours, 0 & $minutes , 0 & $seconds - 03)
    ;_SoundResume($Open)
    ;_SoundPlay ($Open)
    ;_SoundPause ($Open)
    IniWrite("C:\myfile.ini", "section2", "status", "pause")
EndFunc   ;==>_Pause

Func _Seek()
    If $Toggle = False Then Return @error
    If $S_Play = False Then Return @error
    _SoundStop($Open)
    $S = GUICtrlRead($Slider)
    ;If $S = '100' Then _End ()
    $P = (_SoundLength($Open, '2') / '100') * $S
    $P = _Convert($P)
    _SoundSeek($Open, Round($P['1'], '0'), Round($P['2'], '0'), Round($P['3'], '0'))
    _SoundPlay($Open)
EndFunc   ;==>_Seek

Func _HideShow()
    If $Toggle = False Then
        $Toggle = True
        WinSetState($GUI, '', @SW_HIDE)
    Else
        $Toggle = False
        WinSetState($GUI, '', @SW_SHOW)
    EndIf
EndFunc   ;==>_HideShow

Local $GUI_Add
Func _Exit_Add()
    WinSetOnTop($GUI_Add, '', '0')
    GUIDelete($GUI_Add)
    WinSetOnTop($GUI, '', '1')
EndFunc   ;==>_Exit_Add

Func status()

    If $playstatus = 0 And IniRead("C:\myfile.ini", "section2", "status", "") = "pause" Then
        ;_Seek ()
        _Play()
        $playstatus = 1
    ElseIf $playstatus = 1 And IniRead("C:\myfile.ini", "section2", "status", "") = "play" Then
        _Pause()
        $playstatus = 0
    EndIf
EndFunc   ;==>status

Func rewind()
    $pause_pos = _SoundPos($Open)
    ;consolewrite($pause_pos & @CRLF)
    $hours = StringTrimRight($pause_pos, 6)
    $minutes = StringTrimRight(StringTrimLeft($pause_pos, 3), 3)
    $seconds = StringTrimLeft($pause_pos, 6)
    ;consolewrite($seconds & @CRLF)
    ;If $hours + $minutes  + $seconds <= 5 Then _SoundSeek ($Open, 00, 00, 00)
    ;If $hours + $minutes  + $seconds > 5 Then _SoundSeek ($Open, $hours, $minutes  , ($seconds - 5))
    ;consolewrite("Rewind" & $hours & ":" & $minutes  & ":" & $seconds & @CRLF)
    _SoundStop($Open)
    _SoundSeek($Open, $hours, $minutes, ($seconds - 5))
    _SoundPlay($Open)
EndFunc   ;==>rewind

Func _End()
    _SoundStop($Open)
    $S_Pause = True
EndFunc   ;==>_End

You can see my additions by the <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< lines.

However, I do not entirely follow the player code so do come back if it does not work as you want. :huggles:

M23

P.S.

I do not have any other player with GUIOnEventMode and they work, I believe, better than NON-GUIOnEventMode players, which are sometimes unnresposive while playing

Not so. If they are unresponsive it is because they are not coded correctly. :

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

Melba23

Thanks so much for your help. The player works marvelously now, exactly the way I wanted.

Apologies for causing confusion due to the word "exits" in place of "exists". There are some extra function in the code which I failed to delete.

I appreciate very much your help.

Thanks again

Regards

Ajit

Link to comment
Share on other sites

  • Moderators

ajit,

Glad I could help! :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

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...