Android Can't Play Some Wav File With Soundpool?
Solution 1:
I had lots of problems with soundpool and file formats. Read my original question, it might be helpful to you.
Basically, I changed to use MediaPlayer and had no more problems.
Solution 2:
My finding using .WAV resource files with an LG Optimus F3 running Jellybean 4.1.2 is that its MediaPlayer library fails to decode:
- Files whose bitrate exceeds 256kbps, and
- Files whose duration is less than .075 seconds
The symptom in logcat in either case is:
V/SoundPool﹕ load: fd=49, offset=123932, length=536, priority=1
V/SoundPool﹕ create sampleID=3, fd=50, offset=536, length=123932
V/SoundPool﹕ doLoad: loading sample sampleID=3
V/SoundPool﹕ Start decode
V/MediaPlayer﹕ decode(50, 123932, 536)
V/SoundPool﹕ close(50)
E/SoundPool﹕ Unable to load sample: (null)
Rather than generate a fatal exception, the above error causes SoundPool to later attempt to use these "null" sounds, which in turn can cause the phone to lock up and/or lose frames. Reducing the bitrate and using Audacity's "add silence" effect to lengthen the time of my sound files has solved this problem.
In contrast to the symptom above, a successful SoundPool load looks like this in logcat:
V/SoundPool﹕ load: fd=55, offset=765700, length=3534, priority=1
V/SoundPool﹕ create sampleID=7, fd=56, offset=3534, length=765700
V/SoundPool﹕ doLoad: loading sample sampleID=7
V/SoundPool﹕ Start decode
V/MediaPlayer﹕ decode(56, 765700, 3534)
V/SoundPool﹕ close(56)
V/SoundPool﹕ pointer =0x5f464000, size =6976, sampleRate =8000, numChannels =2
If you are loading multiple sounds (which is the purpose of SoundPool), note your sampleID
values as they tell which sound file failed to load, the first one loaded being sampleID=1
, and so on. That helped me distinguish "bad" from "good" .WAV files.
Note that I have not had this problem on several other platforms from LG and Samsung running Android Kitkat, which load higher bitrate and short sound files successfully.
Post a Comment for "Android Can't Play Some Wav File With Soundpool?"