I also wanted to use the soundpool, but lack of documentation made it impossible to use. I tried it they way i would think it would work, but it didn't.
I am using mediaplayers now, i cannot play the same sound multiple times concurrently, Too bad. On 12 okt, 19:32, Robert Green <[EMAIL PROTECTED]> wrote: > 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 forsoundin 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 > samesounda 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? > > Androidreally 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 asoundstream output buffer (so a dev can pipe in > rawsounddata) > > On Oct 11, 5:30 pm, Robert Green <[EMAIL PROTECTED]> wrote: > > > Problem solved. Here's how I did it: > > > This only loads onesoundbut 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(intsound) { > > 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 addingsoundinto my game now and need the ability to havesound > > > 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 traditionalsoundupdate 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 andsoundbuffer. > > > > 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 nosound. 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 android-developers@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---