I want to play a sound while animating a view.
I'm playing the sound with MediaPlayer, and the sound gets interrupted when I play the animation (when I say interrupted, I mean stops as soon as the animation starts).
This happens for both property animations (done using nineoldandroids lib) and also for sequence animation (frame by frame).
The sound code:
MediaPlayer mp = MediaPlayer.create(context , rawSoundFileId);
if (mp == null) {
return;
}
mp.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mp.release();
}
});
if (mp != null) {
mp.start();
}
I also tried moving the sound to a separate thread, and this still happens.
any ideas for resolving this?
As it turns out, is is recommended to use SoundPool to play short sounds. If I load the sounds to the pool in advance, the animation does not interrupt the sound anymore.