Reputation: 41
I'm fairly new to Android so be gentle!
I have the following code, which should (I think) just play "developersshort".
public constructor(Context context){
this.context = context;
soundPool = new SoundPool(2, AudioManager.STREAM_MUSIC,0);
soundPoolMap = new HashMap<Integer, Integer>();
soundPoolMap.put(1, soundPool.load(this.context,
R.raw.developersshort, 1));
}
public void run() {
soundPool.play(soundPoolMap.get(1), 1, 1, 1, 0, 1f);
}
[To try to figure out what's going on, it currently plays that remix of Steve Ballmer shouting "developers" repeatedly! The sound file is ~90KB in size.]
When I run my app in the emulator, and press the button to trigger the sound, it says "developers developers developers..." etc etc, like I would expect.
However, when I deploy it to my phone, all I hear something like "velop" once, and then the sound stops.
I have NO idea what is going on, any ideas?
Thanks a lot!
Upvotes: 4
Views: 2445
Reputation: 23596
Have you try with resampling the sound file ???
Before that my sound file getting cut. But i have converted and resample that m4a from 44KHz to 22KHz and now it works without getting cut. refer this : and again about memory issues with SoundPool
So try like same.
Hope it will works for you.
Upvotes: 1
Reputation: 196
60kb on storage, or 2mb on the heap, decoded, as pure wave MIGHT be the limits, yes. make sure you dont use anything longer than a second or something like that.
soundpool really needs small files. read the SDK page.
Upvotes: 0
Reputation: 85
Is your audio file a .ogg file? It seems like other formats have issues with SoundPool. If that doesn't work you may want to test it with a smaller audio file. I had some glitches when my audio file was over 60kb.
Upvotes: 1