3

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?

PeyloW
  • 36,742
  • 12
  • 80
  • 99

1 Answers1

17

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
  • 36,742
  • 12
  • 80
  • 99
  • 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 Oct 26 '10 at 12:24
  • 9
    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 Oct 26 '10 at 12:43
  • 1
    We loose precious development time with errors like this! I can't believe that this was causing me so many errors with sound. Thanks PeyloW for providing this information! – Nick Nov 18 '15 at 14:39