I've been using SoundPool since Android 1.0 and have always used
workarounds to keep it from crashing.  In 1.5 it became officially
supported so I stopped using my hacks and instead used proper
playSound and stop() for loops.

As it turns out, when the number of streams is less than or equal to
the number of sounds being played concurrently, calling stop() on a
stream which is currently playing causes a freeze.  It never returns.

I found this out on my noisiest level of Light Racer 3D which, when
played with 3 players has:

3 Looping engine sounds
up to 4 charging sounds followed by up to 4 looping electricity sounds
up to 2 power-up sounds
up to 2 explosion sounds

Realistically, the most concurrent sounds being played would 9.  I
have my streams set to 10 to make sure that it's at the lowest setting
that supports everything.  I also use priorities on the samples, just
in case one is cut out.

After releasing the update to my game, I received feedback that on
that level sometimes the game would freeze.  I debugged it down to
that call to SoundPool.stop().

I know that in the past, I've seen SoundPool be sensitive to certain
OGGs that I've thrown at it.  Just re-encoding with a different
setting or a different encoding lib seemed to make a difference.

Either way, I found that SoundPool in its current state on 1.5 is not
bullet proof.  It can still freeze your application.

My workaround for stopping looping sounds is to setLoop(streamId, 0)
and setVolume(streamId, 0,0).  This seems to work fine.  I ran a
longevity test overnight last night, running the same level over and
over with the same soundpool.  It ran for 8 hours like that with no
freezing.

If the soundpool developer (sorry, I forgot your name) needs help in
reproducing this problem, I'd be happy to set up a project that very
quickly causes the error.

Another problem is that when an app running an infinitely looping (-1)
sound crashes, SoundPool will continue to play/loop that sound until
the phone is restarted.  Just thought I'd throw that out there.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to