1. Download our Official Android App: Forums for Android!

Apps Problem with sounds overlapping..

Discussion in 'Android Development' started by b29, May 20, 2010.

  1. b29

    b29 Newbie
    Thread Starter
    Rank:
    None
    Points:
    23
    Posts:
    12
    Joined:
    Apr 2, 2010

    Apr 2, 2010
    12
    29
    23
    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
    Rank:
    None
    Points:
    63
    Posts:
    148
    Joined:
    Sep 14, 2009

    Sep 14, 2009
    148
    26
    63
    Software Developer (Java, C, Web, Unix)
    Birmingham, UK
    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 Newbie
    Thread Starter
    Rank:
    None
    Points:
    23
    Posts:
    12
    Joined:
    Apr 2, 2010

    Apr 2, 2010
    12
    29
    23
    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 Newbie
    Thread Starter
    Rank:
    None
    Points:
    23
    Posts:
    12
    Joined:
    Apr 2, 2010

    Apr 2, 2010
    12
    29
    23

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

Share This Page

Loading...