views:

448

answers:

2

I setup my SoundPool, and load a sound resource as this in onCreate():

soundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 0);
soundId = soundPool.load(this, R.raw.edible_underwear, 1);

And then I try to play this sound twice in a onClick(), one slow mostly in left speaker, and one fast mostly in the right speaker:

soundPool.play(soundId, 0.9f, 0.1f, 0, -1, 0.7f);
soundPool.play(soundId, 0.1f, 0.1f, 0, -1, 1.5f);

No sound can be heard. I have fiddled with the volumes, priorities and rates. So far to no avail. Am I missing something obvious?

A: 

So basically - I think you cannot just to execute this code in some sort of test Activity, you need another component that will play the sound such as MediaPlayer

DroidIn.net
No you do not need a `MediaPlayer` to play sound. `SoundPool` works well, and is intended for use in for example games where you have a small set of samples that you want to play over and over again.
PeyloW
Good to know - thanks
DroidIn.net
+3  A: 

Turns out that SoundPool have two bugs/restrictions.

  1. The sound volume is from 0.0f to but not inclusive 1.0f. Both 1.0f and 0.0f are mute, so you must cap your volume at 0.99f.
  2. Loading samples into the SoundPool that do not fit in ram will not result in an exception being thrown, nor is there a soundId returned that can be checked for failure. So you must look at your logs, and pray to the Android gods that your samples fit on the target device.
PeyloW
I suspect your first point is the problem I am having! Glad someone figured it out. Why would the API use 0.0 _and_ 1.0 as mute?!!
gary comtois
Because if you step back and look at Android as whole, then Android is an inconsistent mess. It is quite obvious that each developer follow their own standards of design, and if it compiles+works, then it is good enough.
PeyloW