ios模拟器 – 是否可以在模拟器上测试iOS4多任务/背景音乐?

前端之家收集整理的这篇文章主要介绍了ios模拟器 – 是否可以在模拟器上测试iOS4多任务/背景音乐?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我已经在Info.plist中添加了UIBackgroundModes属性以具有“audio”的数组条目,并添加调用以设置音频会话:[session setCategory:AVAudioSessionCategoryPlayback 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

猜你在找的iOS相关文章