问题
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?
回答1:
Turns out that SoundPool
have two bugs/restrictions.
- 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.
- Loading samples into the
SoundPool
that do not fit in ram will not result in an exception being thrown, nor is there asoundId
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.
来源:https://stackoverflow.com/questions/1394694/why-is-my-soundpool-mute