是否可以测试模拟器上播放的iOS4多任务/背景音乐? [英] Is it possible to test iOS4 multitasking/background music playing on the simulator?

查看:106
本文介绍了是否可以测试模拟器上播放的iOS4多任务/背景音乐?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已在Info.plist中添加了UIBackgroundModes属性,使其具有数组项"audio",并添加了用于设置音频会话的调用:[session setCategory: AVAudioSessionCategoryPlayback error: &error];.

I have added the UIBackgroundModes property in Info.plist to have an array entry of "audio" and have added the call to setup the audio session: [session setCategory: AVAudioSessionCategoryPlayback error: &error];.

但是,我拥有的唯一测试设备是不支持多任务处理的iPod Touch 2G.我已经尝试过模拟器,但是当我切换到Safari时,音乐停止播放.但是当我切换回我的应用程序时,歌曲继续播放的位置比我离开应用程序时的位置还要远.

However, the only test device I have is the iPod Touch 2G which doesn't support multitasking. I've tried the simulator but the music stops playing when I switch to Safari. But when I switch back to my app, the song continues playing to a farther location than when I left the app.

它似乎继续在后台播放,但是在使用另一个应用程序(Safari)时我听不到我的应用程序的声音.

It seems to have continued playing in the background but I didn't hear the audio of my app while using another app (Safari).

推荐答案

我也遇到了同样的问题.在模拟器中,音频会暂停,当您重新启动音频时,它会继续播放.但是在设备上进行测试后,它运行完美,音频继续在后台播放.我使用的示例代码是

I too had the same issue. In simulator the audio pauses and when you launch it back it resumes playback. But testing on device it worked perfectly and audio continued to play in background. The sample code which i have used is

AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[audioPlayer play];

这篇关于是否可以测试模拟器上播放的iOS4多任务/背景音乐?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆