简体   繁体   English

iPhone App的PhoneGap播放列表问题

[英]PhoneGap Playlist issue with iPhone App

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 我正在创建一个有趣的小应用程序,以便将一些mp3文件播放到PhoneGap应用程序中,并且我设法在后台播放音频,这非常感谢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 greyselected是当前正在播放的歌曲activetrackclass是保存曲目项目的类别的变量,或者track div fetchmp3是调用列表中下一个mp3文件的函数

All mp3 are hosted on a server 所有mp3都托管在服务器上

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. 如果您的应用程序未处于活动状态,则它将永远不会运行,而ios将在一段时间后将其停止。

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

You can declare the support for background playback by specifying audio mode in UIBackgroundModes in Info.plist file. 您可以通过在Info.plist文件的UIBackgroundModes中指定audio模式来声明对后台播放的支持。 Check page 60 of iphone programming guide for more detail 有关更多详细信息,请参阅《 iphone编程指南》第60页

You have lot of options to configure the behavior of the audio if you application can use the native code. 如果您的应用程序可以使用本机代码,则有很多选项可以配置音频的行为。 Check the Categories Express Audio Roles in below docs. 在下面的文档中查看Categories Express Audio Roles

http://developer.apple.com/library/ios/#documentation/Audio/Conceptual/AudioSessionProgrammingGuide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40007875 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 https://devforums.apple.com/message/264397#264397

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM