iOS4.0 iphone应用程序在后台运行时AudioQueueStart失败
当我的应用程序在 iOS4.0 后台运行时,我在启动 AudioQueue 时遇到困难 当应用程序处于活动状态时,代码可以正常工作,但在后台运行时会失败,并显示 -12985 代码。
err = AudioQueueStart( queueObject, NULL );
if( err )
{
NSLog(@"AudioQueueStart failed with %d", err);
= NO;
AudioQueueStop(queueObject, YES);
return;
}
对于上面的代码,err 设置为 -12985
I'm having difficulties starting the AudioQueue when my app is in the background with iOS4.0
The code works fine when the app is active, but fails with -12985 code when running in the background.
err = AudioQueueStart( queueObject, NULL );
if( err )
{
NSLog(@"AudioQueueStart failed with %d", err);
= NO;
AudioQueueStop(queueObject, YES);
return;
}
For the code above, err is set to -12985
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
确保我的 AudioSession 处于活动状态解决了问题:
以前在代码中,我在开始新歌曲之前将会话设置为歌曲更改之间的非活动状态:
AudioSessionSetActive(false);
一旦我删除了这个 AudioQueueStart,它就可以在后台正常工作了。
Making sure that my AudioSession was active fixed the problem:
Previously in code I had set the session to inactive between song changes before starting a new song:
AudioSessionSetActive(false);
Once I removed this AudioQueueStart works just fine from the background.
来自苹果开发者论坛:
...
您要确保您的视图成为第一个控制器,然后调用
n
viewDidLoad
。一旦你这样做了,你的玩家将不再返回NO!From Apple Developer Forums:
...
You to this ensuring your view becomes First Controller and then calling
n
viewDidLoad
. Once you do this, your Player will no longer return NO!!从那以后我了解到,从后台重新使用音频队列效果很好。你就是无法重新开始。
I've since learned that re-using an audioqueue from the background works just fine. You just can't start new.