Many "sound" instances

Hello, I have an idea to add new functionality in my soundboard app.

I would use switch component. In OFF (default) position the user will have the posibillity to play only one sound at a time - what I mean, when user clicks button1, then 1.mp3 will play, but if user clicks button2 while 1.mp3 is still playing, then 1.mp3 immediately stops and 2.mp3 will begin to play.

When switch is in ON position, when user clicks button1 then 1.mp3 will start to play, then if user immediately clicks button2 - 2.mp3 will start to play but 1.mp3 won’t stop until it finishes.

If I have 50-70 buttons connected with sounds then I’ll have to use 50-70 instances of “sound” component, right? Or maybe there is some kind of “trick” to use only 1 sound component?

If it’s not possible with 1 sound component, anybody knows what impact on the app would it be with 50-70 instances of sound component? Will it consume a lot more memory? Would it have an impact on lower-end smartphones? Maybe it’s not a good idea at all?

Cheers,
Beeria

You can use one sound component and change only the source on different button clicks.
No need to add 50 sound components :smile:

Mika
Makeroid Developer

You can use one sound component and change only the source on different button clicks.
No need to add 50 sound components :smile:

Hi Mika,
At this moment I have it just as you say:

when button1.click
set sound1.source to 1.mp3
call sound1.play

when button2.click
set sound1.source to 2.mp3
call sound1.play

All is fine, but if it’s this way, when I click button2 while 1.mp3 is still playing then 1.mp3 stops immediately and starts 2.mp3

So you want to have it like overlays?
Then use two sound components.

1 Like

Mika
Makeroid Developer

So you want to have it like overlays?
Then use two sound components.

Yeah, something like this. Maybe ability to play 3-4 sounds in the same time would be enough so 3-4 sound components are fine.
Thanks for a hint, now I need to think about a logic of this solution:)

Just use a variable to know which sound component was first played.
Then use this variable to play/stop the correct next sound component.

I think I got it.
Once again thank you.
Blocks below, maybe someone will use it in the future - tested on 6 buttons with sounds in total and it works (3 sound components used = max 3 sounds can be played at the same time).

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.