I am trying to loop short (20kb), gapless ogg files with the SoundPool class and cannot get consistent results while testing on hardware. It always plays back perfectly using the emulator but when I test on a Nexus 1, or on a Samsumg Galaxy Tab 10.1 there are audible pops or clicks at every loop point. What is very strange is that while consistent once the application has started, the clicks are slightly different every time I restart the app and on rare occasions (more frequently on the tablet) the loop plays correctly.
The results are no better using MediaPlayer. Is it unreasonable to expect gapless playback of audio loops on android? Surely someone has similar functionality working properly? If so I would love to see an example of how it works.
Thanks!
I used a hack that works fine for single files:
HACK_loopTimer = new Timer();
HACK_loopTask = new TimerTask() {
@Override public void run() {
mMediaPlayer.seekTo(0);
}
};
long waitingTime = mMediaPlayer.getDuration()-mHackLoopingPreview;
HACK_loopTimer.schedule(HACK_loopTask, waitingTime, waitingTime);
Just set mHackLoopingPreview
to a reasonable amount; I'm using 100ms and it is working fine. I have to agree that this is a less than ideal and ugly solution, but at least it does its job.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With