Jump to content
Sign in to follow this  
BobMandel

Two AutoIt Sound Questions

Recommended Posts

BobMandel

First, I just love AutoIt!!!!!!!  I don't know what I would do without it, or how I existed so long without using it.  I have been creating tons of successful scripts for a variety of purposes.

But I have two quick questions about sound management:

(1) Using SoundPlay, is there any way to specify the number of times to play a sound file?  I know I could create a loop, but this is for background sound behind an application.

(2) I understand that to stop playing sound one can use SoundPlay (""), and that works effectively on sound/music initiated by an earlier SoundPlay command.  But how can you create a script that will stop sound/music not initiated through SoundPlay (though another program running)?

Thanks a ton for you help!

Bob

Share this post


Link to post
Share on other sites
Edano

2.) as far as i know there is no way to stop music from another program than turning down the speakers.

1.) take a short look at this: '?do=embed' frameborder='0' data-embedContent>> maybe it helps you ?

there is no param for the number of times to play the sound. but there are some advanced _Sound* functions in helpfile that could do what you want.

E.

Edited by Edano

[color=rgb(255,0,0);][font="'comic sans ms', cursive;"]FukuLeaks[/color][/font]

Share this post


Link to post
Share on other sites
Xandy

Look into this function _SoundPlay($aSnd, $wait= 0).

Here is how you would use it:
- load a sound file to array
$asound= _SoundOpen($filepath)
-has _soundpause, resume, play, stop, seek, close functions
 
-then play the sound _SoundPlay($asound)
 
You can still control the volume with soundsetwavevolume($volume).

Functional gui example, but you have to find the _soundopen( and change the filepath to the path of your sound file )

then it will loop $bgmusic sound, providing a gui with menubar option to set volume

#include <GUIConstants.au3>;this defines $gui_event_close
#include <Sound.au3>
local $soundvolume= 100, $x= 0
local $hgui= guicreate("_SoundPlay Test", 320, 200);creates a gui dialog window
local $menubarvolume= guictrlcreatemenu("Volume");menubar volume option
local $menubarvolumesetvolume= guictrlcreatemenuitem("Volume "&$soundvolume, $menubarvolume);menu item in menubar option
guisetstate();shows the gui dialog window

local $bgmusic= _soundopen(@ScriptDir&"\DW_Menus.wav");load our music from file, your path will be differant to load mp3s, wav other sound formats
_soundplay($bgmusic);Play the music loaded into $bgmusic

do;main loop
    $msg= guigetmsg();returns messages from the gui
    if _soundpos($bgmusic)>= _soundlength($bgmusic) then _soundplay($bgmusic);repeat music
    if $msg= $menubarvolumesetvolume then;somebody fucking clicked setvolume menubar option item
        $x= inputbox("Sound Volume", "Current Sound Volume: "&$soundvolume&@CRLF&"Please enter new volume or ESCAPE", "", 0, default, default, default, default, 0, $hgui);I do the $hgui parameter thing so the the the inputbox popup window doesn't get layered behind the main gui dialog when the the main gui dialog is clicked, It means this dialog won't get lost behind parent window
        if $x<> "" then;grade the user's assignment
            if $x> 100 then $x= 100;I probably don't have to do this
            if $x< 0 then $x= 0;but it seemed like a good idea at the time
            $soundvolume= $x; : v)
            soundsetwavevolume($soundvolume);this works on mp3s and shit too, AutoIt for the win
            guictrlsetdata($menubarvolumesetvolume, "Volume "&$soundvolume);sets the menubar option item with label of current volume
         endif;changing sound volume
    endif;menubarvolume, setvolume
until $msg= $gui_event_close;it's finally over

(CRLF)

I'd like to thank the Earth rq, then the entire AutoIt team and forum.

Edited by Xandy

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  

×