I am creating a small fun application to play some mp3 files into a PhoneGap app
I have managed to play the audio in the background, many thanks to help on StackOverflow
But now the problem is when the app runs in background, or the app is locked, the next songs does not play. I have written the code to play the next song
=======
$(".greyselected").each(function(i) {
if($(this).is(":visible"))
{
activetrackclass = $(this).attr("class").split(" ")[0];
return;
}
});
$("." + activetrackclass).each(function(i){
if($(this).hasClass("greyselected"))
{
fetchmp3($("." + activetrackclass + ":eq(" + parseInt(i+1) + ")").find(".partistname").text(), $("." + activetrackclass + ":eq(" + parseInt(i+1) + ")").find(".ptrackname").text(), $("." + activetrackclass + ":eq(" + parseInt(i+1) + ")").find(".ptrackurl").text(), $("." + activetrackclass + ":eq(" + parseInt(i+1) + ")").find(".spanduration").text(), "tracklist");
$("." + activetrackclass).removeClass("greyselected");
$("." + activetrackclass + ":eq(" + parseInt(i+1) + ")").addClass("greyselected");
$("#divplayer").slideDown("slow");
return false;
}
});
=======
greyselected is the song currently playing
activetrackclass is a variable that holds the class of the track item or track div
fetchmp3 is the function to call the next mp3 file in the list
All mp3 are hosted on a server
When the app is active it plays just fine, but as soon as it goes to background it just plays the song which was actively playing and then stops until the app is made visible again
Would appreciate your valuable help as always
A background task only runs for a period of time, then the OS kills it. If your application is not active then it wont run forever and the ios will stop it after a while.
http://www.macworld.com/article/1164616/how_ios_multitasking_really_works.html
You can declare the support for background playback by specifying
audiomode inUIBackgroundModesinInfo.plistfile. Check page 60 of iphone programming guide for more detailYou have lot of options to configure the behavior of the audio if you application can use the native code. Check the
Categories Express Audio Rolesin below docs.http://developer.apple.com/library/ios/#documentation/Audio/Conceptual/AudioSessionProgrammingGuide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40007875
An old thread from Apple Developer Forum
https://devforums.apple.com/message/264397#264397