iPhone App的PhoneGap播放列表问题

时间:2012-07-05 16:53:39

标签: iphone cordova playlist

我正在创建一个小型有趣的应用程序,将一些mp3文件播放到PhoneGap应用程序中 我已设法在后台播放音频,非常感谢StackOverflow的帮助

但现在问题是当应用程序在后台运行,或者应用程序被锁定时,下一首歌曲无法播放。我已经编写了播放下一首歌的代码

=======

$(".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是目前正在播放的歌曲 activetrackclass是一个变量,它包含轨道项或轨道div的类 fetchmp3是调用列表中下一个mp3文件的函数

所有mp3都托管在服务器上

当应用程序处于活动状态时,它可以正常播放,但只要它进入后台,它就会播放正在播放的歌曲然后停止,直到应用再次显示为止

一如既往地感谢您的宝贵帮助

1 个答案:

答案 0 :(得分:0)

后台任务只运行一段时间,然后操作系统将其杀死。如果您的应用程序未处于活动状态,则它将不会永远运行,并且ios会在一段时间后停止它。

http://www.macworld.com/article/1164616/how_ios_multitasking_really_works.html

您可以在audio文件的UIBackgroundModes中指定Info.plist模式来声明对后台播放的支持。查看iphone programming guide的第60页了解更多详情

如果应用程序可以使用本机代码,则可以使用许多选项来配置音频的行为。查看以下文档中的Categories Express Audio Roles

http://developer.apple.com/library/ios/#documentation/Audio/Conceptual/AudioSessionProgrammingGuide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40007875

来自Apple Developer Forum的旧帖子

https://devforums.apple.com/message/264397#264397