Problem with sounds overlapping..


Last Updated:

  1. b29

    b29 Member This Topic's Starter

    Joined:
    Apr 2, 2010
    Messages:
    12
    Likes Received:
    29
    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!!
     

    Advertisement
  2. markb

    markb Well-Known Member

    Joined:
    Sep 14, 2009
    Messages:
    148
    Likes Received:
    26
    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 (Text):
    1. public SoundPool (int maxStreams, int streamType, int srcQuality)
    2.  
    3. Since: API Level 1
    4. Constructor. Constructs a SoundPool object with the following characteristics:
    5. Parameters
    6. maxStreams  the maximum number of simultaneous streams for this SoundPool object
    7. streamType  the audio stream type as described in AudioManager For example, game applications will normally use STREAM_MUSIC.
    8. srcQuality  the sample-rate converter quality. Currently has no effect. Use 0 for the default.
    9. Returns
    10. a SoundPool object, or null if creation failed
    11.  
    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
     
  3. b29

    b29 Member This Topic's Starter

    Joined:
    Apr 2, 2010
    Messages:
    12
    Likes Received:
    29
    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!
     
  4. b29

    b29 Member This Topic's Starter

    Joined:
    Apr 2, 2010
    Messages:
    12
    Likes Received:
    29

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

Share This Page

Loading...