我正在使用 PhoneGap 构建一个应用程序,即使手机处于锁定/待机状态,它也需要能够播放本地 .mp3 文件。音频播放器采用 HTML5 构建,运行良好,但当我关闭应用程序或关闭手机时音乐停止。
我尝试按照此链接 UIWebView: HTML5 audio pauses in iOS 6 when app enters background
但没有运气...
我用其他导入函数在顶部做了导入代码。我还将 AVFoundation 框架包含在我的目标中。
这是代码在 AppDelegate.m 中的样子
/**
* This is main kick off after the app inits, the views and Settings are setup here. (preferred -iOS4 and up)
*/
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
/* THE GOOD STUFF */
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
BOOL ok;
NSError *setCategoryError = nil;
ok = [audioSession setCategory:AVAudioSessionCategoryPlayback
error:&setCategoryError];
if (!ok) {
NSLog(@"%s setCategoryError=%@", __PRETTY_FUNCTION__, setCategoryError);
}
我在模拟器和 iPhone 5 上试过。
有人能帮忙吗?