Jump to content

How to stop previous sound playing when i open new sound


tskedition
 Share

Recommended Posts

How to stop previous sound playing when new sound opens

hotkeyset("{PAUSE}", "endscript")

$done=0

do

if(PixelGetColor(1179, 132)==6184542) Then SoundPlay("C:\arse\rpm idle11.wav" ,1)

if(PixelGetColor(1179, 132)==8289918) Then SoundPlay("C:\arse\rpm high 1.wav" ,1)

sleep(10)

until $done=1

Func endscript()

tooltip("")

$done=1

exit

EndFunc ;end endscript()

Link to comment
Share on other sites

Change

if(PixelGetColor(1179, 132)==6184542) Then SoundPlay("C:\arse\rpm idle11.wav" ,1)
if(PixelGetColor(1179, 132)==8289918) Then SoundPlay("C:\arse\rpm high 1.wav" ,1)

to

if(PixelGetColor(1179, 132)==6184542) Then
 SoundPlay("")
 SoundPlay("C:\arse\rpm idle11.wav" ,1)
EndIf
if(PixelGetColor(1179, 132)==8289918) Then
 SoundPlay("")
 SoundPlay("C:\arse\rpm high 1.wav" ,1)
EndIf

See if that works more the way you want. Also, the 1 flag will play the sound file all the way thru before the script continues running, you know.

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Link to comment
Share on other sites

  • Moderators

tskedition,

Which part of:

Calling SoundPlay("") can be used to stop a currently playing sound

is difficult to understand? :graduated:

Just do that before playing a new sound: ;)

If PixelGetColor(1179, 132) = 6184542 Then
    SoundPlay("")
    SoundPlay("C:\arse\rpm idle11.wav" ,1)
EndIf

Note that == is only required when making case-sensitive string comparisons. :)

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

  • Moderators

somdcomputerguy,

Using it can slow the script significantly if you do so unnecessarily in a loop, so it is best to keep it to its intended function. :graduated:

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

if i change idle11.wav" ,1) to idle11.wav" ,0) it plays lots of sounds on top of each other .How to make script play loop when pixel color is 6184542 and stop previous sound half way when pixel color changes to 8289918 and play other sound loop .Sound files are about 5 seconds long . sorry my scripting skill is bad and i dont have time to learn all this

Link to comment
Share on other sites

i would not need to play different sounds if i could just make 1 audio file to change its playng speed then different pixel colors would set speed of the sound sort of fast forward. I am just trying to make engine sound to a program that does not have any sound. Program is called Algodoo its 2d phisics simulator and this script would make many people happy.

Link to comment
Share on other sites

Sorry but example didn't change the way script worked for me.My problem is that when pixel color changes first sounds plays to the end and then starts second sound but it needs to start immediately.And when i change 1 to 0 (0= continue script while sound is playing) and pixel does not change,then script plays bits of sounds on top of each other and makes my pc run slow. What am i doing wrong?

I should add that this script is for Algodoo software and i need sound for engine on different rpm.Algodoo has also scripting possibility and i think i can make some part of screen change color from lighter to darker according to engine rpm.Maybe there is another way accomplishing that engine sound its not important what script i use just final effect is important.

Link to comment
Share on other sites

hotkeyset("{PAUSE}", "endscript")
$done=0
do
if(PixelGetColor(1179, 132)=6184542) Then
SoundPlay("")
SoundPlay("C:\arse\rpm idle11.wav",2)
EndIf
if(PixelGetColor(1179, 132)=8289918) Then
SoundPlay("")
SoundPlay("C:\arse\rpm high 1.wav",2)
EndIf
sleep(10)
until $done=1

Func endscript()
tooltip("")
$done=1
exit
EndFunc ;end endscript()

Link to comment
Share on other sites

  • Moderators

tskedition,

My apologies, I did not notice before that you had the "wait" parameter set for your SoundPlay commands. You need to allow the script to continue while the sound is playing, so this parameter must NOT be set. Try this - it works for me when I test it: ;)

HotKeySet("{PAUSE}", "endscript")
$done = 0
Do
    If (PixelGetColor(1179, 132) = 6184542) Then
        SoundPlay("")
        SoundPlay("C:\arse\rpm idle11.wav")
    EndIf
    If (PixelGetColor(1179, 132) = 8289918) Then
        SoundPlay("")
        SoundPlay("C:\arse\rpm high 1.wav")
    EndIf
    Sleep(10)
Until $done = 1

Func endscript()
    ToolTip("")
    $done = 1
    Exit
EndFunc

Now the script will continue and the SoundPlay("") will stop the current sound before playing the new one. :)

Has that solved the problem for you? :graduated:

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

I did change script added more audio files and colors.But still does not work like i want to.Maybe its just my computers fault.So I uploaded video to youtube to explain what final result should look like and to show my problems with script.

http://www.youtube.com/watch?v=3YXjrFxCXLw

HotKeySet("{PAUSE}", "endscript")
$done = 0
Do
    If (PixelGetColor(1179, 132) = 0x333333) Then
        SoundPlay("")
        SoundPlay("C:\arse\rpm 100.wav")
    EndIf
    If (PixelGetColor(1179, 132) = 0x4C4C4C) Then
        SoundPlay("")
        SoundPlay("C:\arse\rpm 150.wav")
    EndIf
If (PixelGetColor(1179, 132) = 0x666666) Then
        SoundPlay("")
        SoundPlay("C:\arse\rpm 200.wav")
    EndIf
    If (PixelGetColor(1179, 132) = 0x808080) Then
        SoundPlay("")
        SoundPlay("C:\arse\rpm 250.wav")
    EndIf
If (PixelGetColor(1179, 132) = 0x999999) Then
        SoundPlay("")
        SoundPlay("C:\arse\rpm 300.wav")
    EndIf
    If (PixelGetColor(1179, 132) = 0xB2B2B2) Then
        SoundPlay("")
        SoundPlay("C:\arse\rpm 350.wav")
    EndIf
If (PixelGetColor(1179, 132) = 0xCCCCCC) Then
        SoundPlay("")
        SoundPlay("C:\arse\rpm 400.wav")
    EndIf
    Sleep(10)
Until $done = 1
Func endscript()
    ToolTip("")
    $done = 1
    Exit
EndFunc
Link to comment
Share on other sites

  • Moderators

tskedition,

A light dawns! ;)

We need to check if the colour has changed or you will keep playing the same sound over and over again. ;)

Perhaps this will work:

HotKeySet("{PAUSE}", "endscript")
$done = 0
$iCurr_Colour = 0 ; This is to store the colour at the moment
Do
 
    $iColour = PixelGetColor(1179, 132)  ; Get the current colour
    Switch $iColour
        Case 0x333333 ; If it is this colour
            If $iCurr_Colour <> $iColour Then ; Has it changed?
                $iCurr_Colour = $iColour ; If so then store it so we do not restart the sound
                SoundPlay("")
                SoundPlay("C:\arse\rpm 100.wav") ; Play the new sound only when the colour changes
            EndIf
        Case 0x4C4C4C
            If $iCurr_Colour <> $iColour Then
                $iCurr_Colour = $iColour
                SoundPlay("")
                SoundPlay("C:\arse\rpm 150.wav")
            EndIf
        Case 0x666666
            If $iCurr_Colour <> $iColour Then
                $iCurr_Colour = $iColour
                SoundPlay("")
                SoundPlay("C:\arse\rpm 200.wav")
            EndIf
        Case 0x808080
            If $iCurr_Colour <> $iColour Then
                $iCurr_Colour = $iColour
                SoundPlay("")
                SoundPlay("C:\arse\rpm 250.wav")
            EndIf
        Case 0x999999
            If $iCurr_Colour <> $iColour Then
                $iCurr_Colour = $iColour
                SoundPlay("")
                SoundPlay("C:\arse\rpm 300.wav")
            EndIf
        Case 0xB2B2B2
            If $iCurr_Colour <> $iColour Then
                $iCurr_Colour = $iColour
                SoundPlay("")
                SoundPlay("C:\arse\rpm 350.wav")
            EndIf
        Case 0xCCCCCC
            If $iCurr_Colour <> $iColour Then
                $iCurr_Colour = $iColour
                SoundPlay("")
                SoundPlay("C:\arse\rpm 400.wav")
            EndIf
    EndSwitch
    Sleep(10)
Until $done = 1
Func endscript()
    ToolTip("")
    $done = 1
    Exit
EndFunc

My only concern is that you may need to run the sound for longer than the wav file lasts. if so then we might need to look at using the Sound.au3 UDF which can restart the sound if needed. :D

M23

Edit: Why does this :graduated:updowngraded editor remove \ from any paths. :)

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

I would add a flag to tell autoit not to stop and restart the sound if the rpm has not changed.

Something like this...

HotKeySet("{PAUSE}", "endscript")
$done = 0
$RPM = 0
Do
    If (PixelGetColor(1179, 132) = 0x333333) And $RPM <> 100 Then
        $RPM = 100
        SoundPlay("")
        SoundPlay("C:\arse\rpm 100.wav")
    EndIf
    If (PixelGetColor(1179, 132) = 0x4C4C4C) And $RPM <> 150 Then
        $RPM = 150
        SoundPlay("")
        SoundPlay("C:\arse\rpm 150.wav")
    EndIf
    If (PixelGetColor(1179, 132) = 0x666666) And $RPM <> 200 Then
        $RPM = 200
        SoundPlay("")
        SoundPlay("C:\arse\rpm 200.wav")
    EndIf
    If (PixelGetColor(1179, 132) = 0x808080) And $RPM <> 250 Then
        $RPM = 250
        SoundPlay("")
        SoundPlay("C:\arse\rpm 250.wav")
    EndIf
    If (PixelGetColor(1179, 132) = 0x999999) And $RPM <> 300 Then
        $RPM = 300
        SoundPlay("")
        SoundPlay("C:\arse\rpm 300.wav")
    EndIf
    If (PixelGetColor(1179, 132) = 0xB2B2B2) And $RPM <> 350 Then
        $RPM = 350
        SoundPlay("")
        SoundPlay("C:\arse\rpm 350.wav")
    EndIf
    If (PixelGetColor(1179, 132) = 0xCCCCCC) And $RPM <> 400 Then
        $RPM = 400
        SoundPlay("")
        SoundPlay("C:\arse\rpm 400.wav")
    EndIf
    Sleep(10)
Until $done = 1
Func endscript()
    ToolTip("")
    $done = 1
    Exit
EndFunc   ;==>endscript

EDIT: pipped to the post.

Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

  • Moderators

JohnOne,

Great minds, eh? :graduated:

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