Apps Problem with sounds overlapping..

b29

Newbie
This will probably be a pretty "moronic question" so please forgive my ignorance!

I'm a hobbyist web developer but decided to delve into the world of Android Apps thanks to my incredible.. :D Anyway.. To the point..

I decided to start with a soundboard to get a handle on how it works.. I've hit up many forums including the

SoundPool | Android Developers

Which was a great help!

My only issue right now is that I can't seem to get the sounds to stop overlapping one another.. Once you push a button the sound starts but if you push another button the previous button keeps playing; overlapping one another. The solution I'm guessing is easy for an experienced developer so any help would be appreciated as I just started learning this language two days ago... I Purchased a ton of books though, and can't seem to find the answer even though I know it's there.. "Just don't think I know where to look" I'm using eclipse and soundpool...

THANKS IN ADVANCE!!
 

markb

Well-Known Member
Hi b29,

Welcome to Android development. I hope you're enjoying it.

I think there's a pretty simple solution to your problem.
The SoundPool constructor takes 3 parameters, and the 1st one specifies the maximum number of simultaneous streams.

Code:
public SoundPool (int maxStreams, int streamType, int srcQuality)

Since: API Level 1
Constructor. Constructs a SoundPool object with the following characteristics:
Parameters
maxStreams	the maximum number of simultaneous streams for this SoundPool object
streamType	the audio stream type as described in AudioManager For example, game applications will normally use STREAM_MUSIC.
srcQuality	the sample-rate converter quality. Currently has no effect. Use 0 for the default.
Returns
a SoundPool object, or null if creation failed

If you set that to 1, then you can only have 1 sound playing at a time.
Hopefully when you start playing a 2nd sound it should stop the 1st one.

I hope that works for you.

If it doesn't, then you could try keeping a track of the streamID returned when you call play(), and then call stop() before you start playing another sound.

Mark
 

b29

Newbie
Thread starter
Thanks markb! I'v been pretty busy lately but I will be sure and give that a try this weekend; I'll let you know how it turns out. I appreciate the reply!
 

b29

Newbie
Thread starter
Hi b29,


I think there's a pretty simple solution to your problem.
The SoundPool constructor takes 3 parameters, and the 1st one specifies the maximum number of simultaneous streams.


Mark


That worked great; I figured there was a simple solution! Thanks again for your help!
 
Top