Sound plays over another sound, How to force that only one sound playes?

76 views
Skip to first unread message

Marek Wach

unread,
Apr 29, 2019, 6:50:49 AM4/29/19
to MIT App Inventor Forum
Hi
I have two canvas on a screen.  Touching each canvas plays a deferent sound. Bouth sounds have "MinimalInterval" set to 3000ms, which is longer than their playing times.  Both sounds play for no more than two seconds.  If I touch the other canvas while the first canvas's sound is still playing they overlap. The sounds play together.
How to force that only one sound can be played?
Thanks.

BodyMindPower

unread,
Apr 29, 2019, 6:56:07 AM4/29/19
to MIT App Inventor Forum
should not be a problem, show your (relevant) blocks ...

Anke

Marek Wach

unread,
Apr 29, 2019, 6:58:36 AM4/29/19
to MIT App Inventor Forum

BodyMindPower

unread,
Apr 29, 2019, 7:38:57 AM4/29/19
to MIT App Inventor Forum
MinimumIntervall means that further Play() will be ignored an NOT that another sound could not be played:

This means you can't play / start the sound again, before the intervall has elapsed.

So, you have to stop Sound1 before playing Sound2 (or use the Player componten and start playing Sound2 if not.isPlaying.Sound1):

Anke

Chris Ward

unread,
Apr 29, 2019, 12:40:56 PM4/29/19
to mitappinv...@googlegroups.com
Hi Marek

It would be better to have just the one Sound component used to play any sound required on demand. You do not need to have a Sound component for each different sound - in most cases, that would be bad practice.

PlaySoundsWithoutOverlay.png


Edit: Changed the names to match your example. Not sure why you are also using vibrate - a little bit OTT don't you think?


BodyMindPower

unread,
Apr 29, 2019, 1:03:29 PM4/29/19
to MIT App Inventor Forum
Hi Chris, that is not possible if you are setting the Minimum Interval to 3000, because you can't play another sound with the same sound player within the Interval.

Anke

ABG

unread,
Apr 29, 2019, 1:34:21 PM4/29/19
to MIT App Inventor Forum
Check out the Player component too.

Look for events that fire when it has completed a sound,
and a block that tells you if a sound is currently playing.

Using those, you can set up a list as a queue of sound file names
waiting to be played.  Add a sound to the list when touched, and
start the sound at slot 1 of the queue if nothing's playing.
When the Player ends, remove item 1 from the queue and
check if there's more to play.  The next sound will be at the new slot 1,
if the queue isn't empty.

ABG

BodyMindPower

unread,
Apr 29, 2019, 1:47:30 PM4/29/19
to MIT App Inventor Forum
As I suggested, of course the player component is the better and more flexible choice for this purpose.

Anke

Marek Wach

unread,
Apr 29, 2019, 2:33:27 PM4/29/19
to MIT App Inventor Forum
Thanks, I'm working on it reading your suggestions.

Chris Ward

unread,
Apr 29, 2019, 3:23:38 PM4/29/19
to MIT App Inventor Forum
@Anke
.... it is not intended to run the sound for 3 seconds, that is just something Marek tried to stop the sounds overlapping?

BodyMindPower

unread,
Apr 29, 2019, 7:31:18 PM4/29/19
to MIT App Inventor Forum
... yes, and that's why your solution does not work.

Chris Ward

unread,
Apr 29, 2019, 8:26:06 PM4/29/19
to MIT App Inventor Forum
... and yet it does work :) 
Reply all
Reply to author
Forward
0 new messages