I have a few more comments on this class.

1)  Is it going to be officially supported?

2)  Here are some problems I've found with it and workarounds I used:

Bug #1) Looping an mp3 crashes around the 8th loop but looping waves
seems to work fine.
Bug #2) SoundPool.stop(streamId) immediately crashes the app.
Bug #3) setRate() with a rate over 1.5 either doesn't work or also
crashes the VM with no exception.

My new workaround for lack of stop():

to stop a stream, call setLoop(streamId, 0) then setVolume(streamId,
0f, 0f). This will stop a loop after it's done but drop the volume so
it seems to the user to have quit right then. After that, you don't
need to call stop() because the stream will clean itself up from the
loop stopping. This worked for me.

Even if they haven't readied it for public use, it's the only suitable
API for sound in games. I looked into using MediaPlayers but if you
have more than a couple of sounds and you need to be able to play the
same sound a few times concurrently, it's just not a feasible
solution.

I'm really surprised that there is no access to the audio buffer. How
are we supposed to write dynamic audio generation apps?

Android really needs 2 things to be competitive with the audio side:

1) Public access to the media decoders (so a dev can decode an mp3
into raw)
2) Public access to a sound stream output buffer (so a dev can pipe in
raw sound data)

On Oct 11, 5:30 pm, Robert Green <[EMAIL PROTECTED]> wrote:
> Problem solved.  Here's how I did it:
>
> This only loads one sound but you can load as many as you want. I have
> an mp3 in my res/raw directory called explosion.mp3.
>
> Java:
>
>           public static final int SOUND_EXPLOSION = 1;
>           public static final int SOUND_YOU_WIN = 2;
>           public static final int SOUND_YOU_LOSE = 3;
>
>           private SoundPool soundPool;
>           private HashMap<Integer, Integer> soundPoolMap;
>
>           private void initSounds() {
>                soundPool = new SoundPool(4, AudioManager.STREAM_MUSIC,
> 100);
>                soundPoolMap = new HashMap<Integer, Integer>();
>                soundPoolMap.put(SOUND_EXPLOSION,
> soundPool.load(getContext(), R.raw.explosion, 1));
>           }
>
>           public void playSound(int sound) {
>                AudioManager mgr = (AudioManager)
> getContext().getSystemService(Context.AUDIO_SERVICE);
>                int streamVolume =
> mgr.getStreamVolume(AudioManager.STREAM_MUSIC);
>                soundPool.play(soundPoolMap.get(sound), streamVolume,
> streamVolume, 1, 0, 1f);
>           }
>
>           public void update() {
>                if (isExploding()) {
>                      playSound(SOUND_EXPLOSION);
>                }
>           }
>
> On Oct 11, 12:11 pm, Robert Green <[EMAIL PROTECTED]> wrote:
>
> > I'm adding sound into my game now and need the ability to have sound
> > effects concurrent (like 2 of the same explosion playing at the same
> > time, etc) so using the MediaPlayer is less than optimal for me. I was
> > thinking of just adding a traditional sound update into the main loop
> > which would probably work and isn't _that_ hard to write but I don't
> > think I have access to the decoder and sound buffer.
>
> > I found a class called SoundPool that appears to be suited for exactly
> > what I'm trying to do however the documentation is very weak 
> > -http://code.google.com/android/reference/android/media/SoundPool.html
>
> > Has anyone used this with success? If so, could I see a little code
> > snippet?
>
> > I tried this:
> > Java:
>
> >           private void initSounds() {
> >                // 4 streams
> >                // stream type 3 is music
> >                soundPool = new SoundPool(4, 3, 100);
> >                int explosionSound = soundPool.load(getContext(),
> > R.raw.explosion, 1);
> >                soundPool.play(explosionSound, 100, 100, 1, 0, 1);
> >           }
>
> > but it didn't appear to do anything. I didn't get errors but I also
> > heard no sound. Perhaps I need to configure something for the emulator
> > to work like that?
>
>
--~--~---------~--~----~------------~-------~--~----~
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