Creative COW SIGN IN :: SPONSORS :: ADVERTISING :: ABOUT US :: CONTACT US
Creative COW's LinkedIn GroupCreative COW's Facebook PageCreative COW on TwitterCreative COW's Google+ PageCreative COW on YouTube
ADOBE FLASH:HomeFlash ForumFlash TutorialsFlash Video TutorialsWeb Streaming ForumAdobe FlashPodcast

making a soundboard, how to lower background music when other sounds play?

COW Forums : Adobe Flash

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Share on Facebook
Robert Fiorentinomaking a soundboard, how to lower background music when other sounds play?
by on Aug 6, 2012 at 3:17:29 am

I am making a sound board and have background music playing. I want the background music volume to lower when I play other sounds on the soundboard and then come back up after a sound clip has finished playing. I'm a total noob and have made basic soundboards in the past but I've always had the sounds just play over the background music and it's hard to make out the sounds a lot of times. Please help!


Return to posts index
Reply   Like  

Sam MatternRe: making a soundboard, how to lower background music when other sounds play?
by on Aug 10, 2012 at 12:29:55 pm

I think the general answer to your question is you need to be monitoring when your clip starts playing and when it ends. It's simple to know when to lower the volume: when the user clicks on the button to play the clip. You just need to add a line of code above your sound clip play code that sets the background volume lower. Probably makes sense to write a function to lower the sound, and one to raise it, since you'll be calling it a lot.

To detect the end of the soundclip, you need to add an event listener. Something like this for AS3.

soundClip1.addEventListener(Event.SOUND_COMPLETE, raiseVolume);

This calls the "raiseVolume" function when your clip is done playing.

This page has a lot of information on Sounds, Sound Channels, and Sound Transforms, all of which are required for the above.
http://www.republicofcode.com/tutorials/flash/as3sound/

-Sam


Return to posts index
Reply   Like  

Robert FiorentinoRe: making a soundboard, how to lower background music when other sounds play?
by on Aug 10, 2012 at 2:30:19 pm

Thanks Sam, that makes sense with what I've been learning in my basic Flash book. I have a concern though, and that's how that code would effect if I played multiple sound clips at the same time (which happens on my sound board).

Instead of having each one lower the volume to nothing or less than nothing, then raise the volume as they each end, would it be possible to have each sound clip set the background volume to a fixed amount (say, 25%) and then when finish put it back to 100%?

Is there a way to have Flash able to detect if any sound is playing, and then have the background lowered when that indicator's on?


Return to posts index
Reply   Like  


Sam MatternRe: making a soundboard, how to lower background music when other sounds play?
by on Aug 10, 2012 at 3:08:45 pm

First, do you want multiple sounds to be able to be played at the same time? If not, I would:

Create a function like "function playClip( whatClip ):void{}" that you can use to play each clip. When a user hits a button, you would call "playClip("clipName");" where "clipName" is the name of the sound that you want to play.

Inside the function, set the volume of the background music to 25%, which I believe is a static value, not a cumulative. Meaning, if the background volume level is already 25%, I don't think it will reduce it to 25% of that if called again. I think it will just remain at 25% of it's original volume. Then set your sound to the whatClip variable and play it, which will STOP any currently playing clip and play the new one. Then set the eventListener I linked to before, listening for your clip to stop.

Create the function to return the volume up (and you should also remove the listener at that point).

If you DO want multiple clips to play, it gets a bit trickier. You can accomplish it several different ways. What I would probably do is:
Create a boolean variable for each clip at the beginning of your code like "clip1:Boolean = false;". When a clip1 starts playing, set "clip1 = true;". When it stops, call a function like "clip1Stop". Inside of clip1Stop, set "clip1 = false;" and then call "volumeUp();". Inside the volumeUP function have an if statement like:
"if (clip1 == false && clip2 == false && clip3 == false && clip 4 == false etc){ volume = 100; }".

Of course, that is pseudo-code, but hopefully you get the idea. That way if two clips are playing, they are both set to true. If clip1 finishes while clip2 is still playing, it gets set to false and makes it to the if statement inside of volumeUp. However, clip2 is still set to true, so the volume won't go back up until clip2 is set to false (the next time the volumeUp function will run) assuming no others have been played.

The only thing that stinks is that you have to create a stop function for EACH clip (clip1stop, clip2stop, clip3stop). All the function is there for is setting that clip to false and then calling volumeUp. This is a "limitation" of AS3's event call. It would be awesome to call "Event.STOP, stopClip('clip1')" but it's not possible from my recollection.

-Sam


Return to posts index
Reply   Like  

Robert FiorentinoRe: making a soundboard, how to lower background music when other sounds play?
by on Aug 11, 2012 at 9:35:32 pm

Is it possible to use a math formula, like in each play clip function have something like "soundsPlaying = +1" and then when soundsPlaying > 0, the background volume is lowered? Each clip would have a soundsPlaying +1 at the start, a soundsPlaying -1 at the end, and then if multiple clips are playing the soundsPlaying value might be 3 for instance, and when they're all done playing it'll be back at zero and the normal volume can resume.


Return to posts index
Reply   Like  

Sam MatternRe: making a soundboard, how to lower background music when other sounds play?
by on Aug 13, 2012 at 12:59:16 pm

Yes, that should work as well.

-Sam


Return to posts index
Reply   Like  

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
Share on Facebook


FORUMSTUTORIALSMAGAZINESTOCKYARDVIDEOSPODCASTSEVENTSSERVICESNEWSLETTERNEWSBLOGS

Creative COW LinkedIn Group Creative COW Facebook Page Creative COW on Twitter
© 2013 CreativeCOW.net All rights are reserved. - Privacy Policy

[Top]