前端之家收集整理的这篇文章主要介绍了
ios模拟器 – 是否可以在模拟器上测试iOS4多任务/背景音乐?,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我已经在Info.plist中
添加了UIBackgroundModes
属性以具有“au
dio”的数组条目,并
添加了
调用以设置音频会话:[session setCategory:AVAu
dioSessionCategoryPlayback error:& error] ;.
但是,我唯一的测试设备是不支持多任务的iPod Touch 2G.我尝试过模拟器,但当我切换到Safari时,音乐停止播放.但是当我切换回我的应用程序时,这首歌继续播放到比我离开应用程序更远的位置.
它似乎在后台继续播放,但我没有听到我的应用程序的音频,而使用另一个应用程序(Safari).
我也有同样的问题.在模拟器中,音频暂停,当您启动它时,它将恢复播放.但测试在设备上它的工作完美,音频继续播放在
后台.我使用的示例
代码是
AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[audioPlayer play];
原文链接:https://www.f2er.com/iOS/330060.html