Search code examples
cordovaphonegap

PhoneGap audio lag


I use javascript to play a short sound on my app:

var audio = new Audio('sound.mp3');
audio.play();

When the above code is called, the whole app gets a lag/delay. After about 200-500ms the app continues as normal and plays the sound. After playing the sound for 2-3 times it seems to have cached or something, because then it works as it should without a lag.

This happens when testing in PhoneGap app for iOS. Running in Chrome desktop it works good.


Solution

  • You may consider loading the sound when you app is launched and keep it in the cache. Then, just play it when needed. That should reduce the lap or even omit it.