Jump to content

Sound help


 Share

Recommended Posts

So I have some questions about sound functions.I'll start with the one that might help me resolve other preoblems regarding sound.

I know I can use _SoundPos($sound, 2) to get the position of sound and I need something like If _SoundPos($sound, 2) => 5000 then something.So, how can I use _SoundPos($sound, 1) => 00:00:05 ?It's not working this way and getting the time in hh:mm:ss might help me in this case.I will post my code too if this doesn't do what I want..

Thank you for your help.

Link to comment
Share on other sites

_SoundPos($sound, 1) => 00:00:05

You cannot compare a string because its numerical representation is always zero, what is the problem when you use _SoundPos($sound, 2) => 5000

Use this otherwise

#include <Date.au3>


$sTime = "00:00:05"
$aSoundTick = StringRegExp($sTime, "[^:]+", 3)

$iTicks = _TimeToTicks($aSoundTick[0], $aSoundTick[1], $aSoundTick[2])

MsgBox(0, 0, $iTicks)

;Use this otherwise
#cs
;If _SoundPos($sound, 2) => $iTicks Then
#ce

or this - into one function

$sTime = "00:00:05"
MsgBox(0, 0, _TimeToTicksEx($sTime))

Func _TimeToTicksEx($iString)

$aSoundTick = StringRegExp($sTime, "[^:]+", 3)
$iHours = $aSoundTick[0]
$iMins = $aSoundTick[1]
$iSecs = $aSoundTick[2]

If StringIsInt($iHours) And StringIsInt($iMins) And StringIsInt($iSecs) Then
Local $iTicks = 1000 * ((3600 * $iHours) + (60 * $iMins) + $iSecs)
Return $iTicks
Else
Return SetError(1, 0, 0)
EndIf
EndFunc   ;==>_TimeToTicksEx

#cs

If _SoundPos($sound, 2) => _TimeToTicksEx("00:00:05") Then

#ce
Regards :) Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

Thanks for the methods.

Ok.I messed around a bit with the first one and it does the same thing my function does.The second one seems about the same.And some dum question :

In $iTicks = _TimeToTicks($aSoundTick[0], $aSoundTick[1], $aSoundTick[2]) what are [0], [1] and [2] for?Are they like tick for hour [0], tick for minutes [1] and tick for seconds [2] ?( i don't really get how this tick thing works)

But anyway it does the same thing as my function (loopmusc()).I think I need to use something different like update cause what I want is to play a song when gui starts (did this) and loop the song.I also have some buttons and while the button b1 runs a script the song will loop after another 5 seconds(loops the song every 8-9 seconds instead of every 5 seconds when the b1 script is running) and I think i would need an update function or something like that for the song when it's running another script..

I attached the files here and if you have any idea please tell me what i sould do.It 's quite some disorder because I tested your function for button b1 and for gui, but it's the same if you replace that soundtick lines with loopmusc()

I appreciate your help.

guitry.zip

Link to comment
Share on other sites

  • Moderators

trnew,

I get an archive error when I try to extract the files - could you try again please. :)

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

When no button pressed - Loop the whole song

But1 - Loop every 5Secs

But2 - Loop every 8Secs

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Sound.au3>
#include <WinAPI.au3>
#include <Date.au3>


Global $blmusicstop = False, $blmusvol = False, $blloopmus = False
;~ Global $sTime = "00:00:05"
;~ Global $aSoundTick = StringRegExp($sTime, "[^:]+", 3)

;~ Global $iTicks = _TimeToTicks($aSoundTick[0], $aSoundTick[1], $aSoundTick[2])

#region ### START Koda GUI section ### Form=
$hGUI = GUICreate("window", 301, 301)
$iButton1_5Secs = GUICtrlCreateButton("5Secs", 150, 150)
$iButton2_8Secs = GUICtrlCreateButton("8Secs", 190, 190)

GUISetState(@SW_SHOW, $hGUI)
WinSetOnTop("window", "", 1)


Global $sound = _SoundOpen(".\resourc\play.wmv")
_SoundPlay($sound)

HotKeySet("{m}", "Stopmusic")
HotKeySet("{v}", "musvol")
HotKeySet("{ESC}", "Terminate")

$iLoopin = 0 ;Loop the whole song
While 1

$iMsg = GUIGetMsg()
Switch $iMsg
Case $GUI_EVENT_CLOSE
Exit

Case $iButton1_5Secs
$iLoopin = 5000


MouseMove(600, 700)
MouseClick("")
Sleep(1000)
MouseMove(800, 600)
MouseClick("")




Case $iButton2_8Secs
$iLoopin = 8000

;~ loopmusc()

WinSetOnTop("window", "", 0)
WinSetOnTop("Help", "", 1)
MsgBox(0, "Help", "bla" & @LF & "bla2")
WinSetOnTop("window", "", 1)

EndSwitch
Sleep(10)

If _SoundStatus($sound) = "stopped" Then
_SoundSeek($sound, 0, 0, 0)
_SoundPlay($sound)
EndIf

If $iLoopin > 0 Then

If _SoundPos($sound, 2) >= $iLoopin Then
_SoundSeek($sound, 0, 0, 0)
_SoundPlay($sound)
EndIf

EndIf

WEnd

Func Stopmusic() ; stopmusic function
$blmusicstop = Not $blmusicstop

If $blmusicstop Then
_SoundPause($sound)
Else
_SoundResume($sound)
EndIf
EndFunc ;==>Stopmusic

Func musvol()

$blmusvol = Not $blmusvol

If $blmusvol Then
SoundSetWaveVolume(0)
Else
SoundSetWaveVolume(100)
EndIf

EndFunc ;==>musvol

Func Terminate() ; the exit function
Exit
EndFunc ;==>Terminate
Please ask if I got it wrong

Edit: @m23

Try with 7-Zip, with WinRAR I even failed

Regards :)

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

  • Moderators

PhoenixXL,

That worked - thanks. :)

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

Sorry.I think I confused you.What I wanted was looping the sound (not specifically 5 or 8 seconds)..I really looked in the soundstatus, but I didn't know I could = it with values like "stopped" or "parked", because the example didn't use it like that (still don't know why i didn't try it) ..

I have another problem now When I click button b2 it will show a messagebox, but if I wait till the song stops, it doesn't loop anymore, also when the messagebox is up no hotkeys work..I think it's because it's another window, but then how can I give focus to both windows ( both the GUI and the messagebox ) so that the message box will stay on top of the GUI and the hotkeys will work and the sound will loop?

Here's the cleaned code :

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Sound.au3>
#include <WinAPI.au3>
#include <Date.au3>
Global $blmusicstop = False, $blmusvol = False, $blloopmus = False
#region ### START Koda GUI section ### Form=
$hGUI = GUICreate("window", 301, 301)
$iButton1 = GUICtrlCreateButton("b1", 150, 150)
$iButton2 = GUICtrlCreateButton("b2", 190, 190)
GUISetState(@SW_SHOW, $hGUI)
WinSetOnTop("window", "", 1)
#endregion ### END Koda GUI section ###
Global $sound = _SoundOpen(".\resourc\play.wmv")
_SoundPlay($sound)
HotKeySet("{m}", "Stopmusic")
HotKeySet("{v}", "musvol")
HotKeySet("{ESC}", "Terminate")
While 1

$iMsg = GUIGetMsg()
    Switch $iMsg
  Case $GUI_EVENT_CLOSE
   Exit
Case $iButton1
while 1
If _SoundStatus($sound) = "stopped" Then
_SoundSeek($sound, 0, 0, 0)
_SoundPlay($sound)
EndIf

mousemove(600,700)
mouseclick("")
sleep(1000)
mousemove(800,600)
mouseclick("")
WEnd

Case $iButton2
Sleep(10)
If _SoundStatus($sound) = "stopped" Then
_SoundSeek($sound, 0, 0, 0)
_SoundPlay($sound)
EndIf

WinSetOnTop("window", "", 0)
WinSetOnTop("Help", "", 1)
 MsgBox(0, "Help", "bla" & @LF & "bla2")
WinSetOnTop("window", "", 1)
EndSwitch
Sleep(10)
If _SoundStatus($sound) = "stopped" Then
_SoundSeek($sound, 0, 0, 0)
_SoundPlay($sound)
EndIf

WEnd


Func Stopmusic() ; stopmusic function
 $blmusicstop = Not $blmusicstop
 If $blmusicstop Then
  _SoundPause($sound)
 Else
  _SoundResume($sound)
EndIf
EndFunc ;==>toggle pause/resume
Func musvol()
 $blmusvol = Not $blmusvol
 If $blmusvol Then
  SoundSetWaveVolume(0)
 Else
  SoundSetWaveVolume(100)
 EndIf
EndFunc ; ==>toggle sound on/off

Func Terminate() ; the exit function
  Exit
EndFunc   ;==>Terminate
Link to comment
Share on other sites

  • Moderators

trnew,

MsgBox is an API blocking function so nothing in the script works until you return. I suggest using my ExtMsgBox UDF - look in my sig for the link - as that allows the HotKeys to remain active. :)

M23

Edit: 15k!

Edited by Melba23

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

You would need another process for asynchronous MsgBox

Have a look

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Sound.au3>
#include <WinAPI.au3>
#include <Date.au3>
Global $blmusicstop = False, $blmusvol = False, $blloopmus = False, $pid
#region ### START Koda GUI section ### Form=
$hGUI = GUICreate("window", 301, 301)
$iButton1 = GUICtrlCreateButton("b1", 150, 150)
$iButton2 = GUICtrlCreateButton("b2", 190, 190)
GUISetState(@SW_SHOW, $hGUI)
WinSetOnTop("window", "", 1)
#endregion ### END Koda GUI section ###
Global $sound = _SoundOpen(".\resourc\play.wmv")
_SoundPlay($sound)
HotKeySet("{m}", "Stopmusic")
HotKeySet("{v}", "musvol")
HotKeySet("{ESC}", "Terminate")
While 1

$iMsg = GUIGetMsg()
Switch $iMsg
Case $GUI_EVENT_CLOSE
Exit
Case $iButton1
While 1
If _SoundStatus($sound) = "stopped" Then
_SoundSeek($sound, 0, 0, 0)
_SoundPlay($sound)
EndIf

MouseMove(600, 700)
MouseClick("")
Sleep(1000)
MouseMove(800, 600)
MouseClick("")
WEnd

Case $iButton2
Sleep(10)
;Doesn't required since its in the main loop
;~ If _SoundStatus($sound) = "stopped" Then
;~ _SoundSeek($sound, 0, 0, 0)
;~ _SoundPlay($sound)
;~ EndIf

WinSetOnTop("window", "", 0)
WinSetOnTop("Help", "", 1)
MsgBoxAsync(0, "Help", "bla" & @LF & "bla2", 0, $hGUI)
WinSetOnTop("window", "", 1)
EndSwitch
Sleep(10)
If _SoundStatus($sound) = "stopped" Then
_SoundSeek($sound, 0, 0, 0)
_SoundPlay($sound)
EndIf

WEnd


Func Stopmusic() ; stopmusic function
$blmusicstop = Not $blmusicstop
If $blmusicstop Then
_SoundPause($sound)
Else
_SoundResume($sound)
EndIf
EndFunc ;==>Stopmusic
Func musvol()
$blmusvol = Not $blmusvol
If $blmusvol Then
SoundSetWaveVolume(0)
Else
SoundSetWaveVolume(100)
EndIf
EndFunc ;==>musvol

Func Terminate() ; the exit function
ProcessClose($pid)
Exit
EndFunc ;==>Terminate

Func MsgBoxAsync($iFlag, $sTitle, $sText, $iTimeout = 0, $Hwnd = 0)
$pid = Run(@AutoItExe & ' /AutoIt3ExecuteLine "MsgBox( ' & $iFlag & ', ""' & $sTitle & '"", ""' & $sText & '"", ' & $iTimeout & ', ' & $Hwnd & ')"')
EndFunc

edit : M23's suggestion should be more helpful

Regards :)

Edited by PhoenixXL

My code:

PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Link to comment
Share on other sites

Let me be the first to say it

Congrats! :thumbsup:

--

@PhoenixXL

Let me thank you very much.That was exactly what I needed.Now I'll look more into all that. :)

---

@Melba23

I'd try it that way, but I want to understand a function and your function is just...way too complicated for me to understand.

----

Well, I do have some questions:

In MsgBoxAsync(0, "Help", "bla" & @LF & "bla2", 0, $hGUI) I have to mention $hGUI so that the msgbox window would have the same properties as $hGUI has and only then it will be on top?( I don't really understand how it works )

In Func MsgBoxAsync($iFlag, $sTitle, $sText, $iTimeout = 0, $Hwnd = 0, $iExit = False) what is $iExit?Is there a full list with those $variables (like $iFlag...) autoit works with(not just the ones for the msgbox function)?

Thank you.

Edited by trnew
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...