Stop tagged audio from playing?

Get help using Construct 2

Post » Wed Oct 24, 2012 12:39 pm

I want to press a button and stop all audio tagged "FX" from playing. Whether it's playing at the time or going to be played in the future. I tried the muted event, but the sounds keep on playing.

Should that do it or is there another way? Thanks.
B
19
S
3
G
2
Posts: 212
Reputation: 4,011

Post » Wed Oct 24, 2012 6:01 pm

This is for Chrome (latest versions always), as it seems to have the best support for HTML5 audio right now.

First, click on the audio plugin in the project folder window. Make sure on the left that audio timescale is turned on.

Also, it seems to depend on which folder you use for audio. If you put it in the "music" folder, then audio will pause correctly when timescale is "0". If audio is in the "sounds" folder, this doesn't work for some reason.

If you tell any audio to stop when a certain button is pressed (e.g. On Keyboard Button 'A' pressed, Stop audio), that should work. It works just fine for me. If you tell it to mute (like for looping ambient sounds), that should work too.

Like I said, make sure you have the audio timescale turned on. Play around with the 2 different settings ("sounds" and "sounds and music").

In Chrome I've managed to get most things to work properly.
B
14
S
5
G
4
Posts: 121
Reputation: 3,938

Post » Wed Oct 24, 2012 10:47 pm

Thanks @ptbcomposer I'll give it a go and let you know.
B
19
S
3
G
2
Posts: 212
Reputation: 4,011

Post » Thu Oct 25, 2012 1:48 pm

@ptbcomposer I set timescale to ON and moved the sound in to the music folder but still no joy.

Further tests show that the "mute button" works when the FX sound is playing at the time.

So, it's muting the sound but not stopping it from playing. Is there a command that disables a sound from playing in the future?
B
19
S
3
G
2
Posts: 212
Reputation: 4,011

Post » Thu Oct 25, 2012 6:45 pm

No, no, no...you have to use the "Stop Playback" event. Of course the sound is still playing when you mute it. Think of this like you're watching a recording on TV. You press mute, but playback is still happening. You just can't hear it. On the other hand, if you hit stop, then playback stops. Look at my response to this post...

http://www.scirra.com/forum/topic53670.html
B
14
S
5
G
4
Posts: 121
Reputation: 3,938

Post » Thu Oct 25, 2012 7:06 pm

Sorry, I forgot to answer the other question...no, I don't think there is any way to prevent a sound from playing. The only way I can think of is to disable it yourself on the event sheet. Why would you want to do that anyway? If you don't want the sound to play, don't have an event for it.
B
14
S
5
G
4
Posts: 121
Reputation: 3,938

Post » Thu Oct 25, 2012 8:23 pm

It's a "disable sound effects" button. If the player doesn't want to hear effects, they can press the button (once) to silence them. I tried your answer in the other thread but it didn't act any different.

I'm going to try this plugin. Thanks for your help.
http://www.scirra.com/forum/plugin-appmobi-plugin-updates_topic55572.htmlkenhes2012-10-25 20:57:28
B
19
S
3
G
2
Posts: 212
Reputation: 4,011

Post » Thu Oct 25, 2012 11:52 pm

Check this out. Make sure every sound you want to mute is tagged with the same tag (in my case it is "sfx"). Create a global variable called "SFXAudio" or "SFXMute" whatever and then follow this code...



When global variable is 0, "sfx" is muted. When global variable is 1, "sfx" is unmuted. Simple. For some reason Construct 2 buttons don't work with it, so use your own as a sprite or something (in my case here it is a text box).
B
14
S
5
G
4
Posts: 121
Reputation: 3,938

Post » Thu Oct 25, 2012 11:53 pm

I didn't know that's what you were trying to do. Sorry.

Also, you can use that for anything you want to mute, such as ambient sounds and music. Just remember to tag everything correctly, and create a global variable for them.
B
14
S
5
G
4
Posts: 121
Reputation: 3,938

Post » Thu Oct 25, 2012 11:57 pm

Oh, and I just tried. This works even when switching between browser tabs.
B
14
S
5
G
4
Posts: 121
Reputation: 3,938

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 20 guests