0
votes

I'm working on Intel xdk, which is based on phonegap 3.5.1. Testing on android 4.4.4 and 5.0.1

Using media api, I'm trying to play audio for a defined duration, after which next audio should start, and thus loop on.

For this I'm using setTimeout for delay until one audio ends.

The audio needs to play in background as well.

Now the problem is, even when audio is playing and looping as expected, setTimeout doesn't get fired in background and audio keeps on playing.

Also, the results are inconsistent, quite accurate on Android 4.4.4 but highly varying on Android 5.0.1.

Please suggest what to do? Can I buffer audios or concatenate audio files to prepare one single file with defined durations and then play complete file? If yes, how?

1

1 Answers

0
votes

The issue is when your app is backgrounded, JS execution is paused in the WebView. This is why the setTimeout will not be triggered.

There was another similar question - Timer Task rung in background Javascript or Cordova App They have links to a plugin you can use for background services, which is what you will need to be able to switch audio tracks.