Arif Nadeem
Arif Nadeem

Reputation: 8604

Android SoundPool Class acts weird in my application

I have a song playing continuously in background using an Android MediaPlayer, by continuously I mean it loops forever.

I also have 25-30 short sounds that I play at discrete duration's using SoundPool Class, and they also have to play again and again with the main song.

The sounds are 0.5 second duration each and some of them are 0.7Mb in size, while the average size of a song would be approximately 0.4Mb.

I am able to do this entire thing smoothly on the device I made this app on, then I came to know that SoundPool has problems playing on Dual Core Phones. So I withdrew support for them.

Lately I tested the app on an older device running 2.3.3 and the new problem is that the sounds seem to play properly for first 4-5 cycles, i.e. till the main song plays 4-5 times, then at 6th time, there is a noticeable delay in the playing of sounds, I logged the values of SoundPool.play() and found out that delay is ~(1-2 sec), and this issue is only on lower end phones, why is this happening, I suppose that the problem is caused by the SoundPool class and is not at all an hardware issue since the device I tested it on had ample RAM i.e. 500Mb and a decent 600Mhz processor.

I really need to fix this as I expect my app to run on most devices, except dual core phone for time being.

Also I cannot use MediaPlayer to play my sounds as I do not want to increase CPU overhead and make my app lag more and also I do not know how many sounds I want to play before hand.

Any clue on how to fix this issue and reduce the lag, is most welcome.

Upvotes: 0

Views: 327

Answers (1)

zapl
zapl

Reputation: 63955

Audio / Video playback is usually problematic since there are a lot of hardware / lowlevel software factors involved (there might be specialized decoding hardware on separate chips and/or embedded into the cpu and all of that in combination with software decoders, switching between bluetooth, headphonejack and the 2 speakers you have, a huge software stack from kernel to android system, etc). It is probably the most fragile subsystem of Android devices. A lot of devices have smaller quirks in that area and it isn't directly Mhz / RAM / Dualcore related. And unfortunately you have to live with some of them :(

Your best bet is to experiment with different ways to play / compress your audio. Things like restarting the playback after 5 cycles etc

Upvotes: 1

Related Questions