iOS4进入后台播放音频 [英] Entering background on iOS4 to play audio

查看:20
本文介绍了iOS4进入后台播放音频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在谈到在后台播放音频时,文档写得相当糟糕.它给人的印象是,要继续播放当前正在播放的音频,您只需在 info.plist 文件中添加一个键/值对即可,这太神奇了.

The documentation is rather poorly written when talking about playing audio in the background. It gives the impression that all you have to do to continue playing the audio that you are currently playing is to just add a key/value pair to the info.plist file and wallah, it's magic.

但是,事实并非如此.例如,如果我播放 2 分钟长的 mp3,显然音频足够长,可以在我按下主页按钮将我的应用程序发送到后台后播放.问题是,即使我的 info.plist 文件中有该键/值对,它也会暂停音频,然后在我切换回应用程序后继续播放.

However, this is not the case. For instance, if I play an mp3 that is 2 minutes long, obviously the audio is long enough to be able to play after I hit the home button to send my app to the background. The thing is, even though I have that key/value pair in my info.plist file, it pauses the audio and then resumes playing once I switch back to the app.

Apple 声明所有音频框架都支持背景,并且声音应继续播放直到结束,然后 Apple 将暂停您的应用.

Apple states that all frameworks for audio support background and the sound should continue playing up until the point that it ends and then Apple will suspend your app.

所以,我的问题是:他们在做什么而我错过了?我是否还必须以某种方式使用他们的新代表或调用 applicationDidEnterBackground 上的音频?对我来说,这没有任何意义,因为我没有保存状态(他们为我做的快速应用程序切换)或真正在后台处理除了他们说应该自动处理的音频之外的任何内容.

So, my question is: What are they doing that I am missing? Do I also have to use their new delegates somehow or call the audio on the applicationDidEnterBackground? To me, that wouldn't make sense since I am not saving state (they do for me with fast app switching) or really handling anything in the background other than audio which they say is supposed to be handled automagically.

推荐答案

文档中缺少的一部分是您需要设置音频会话.

The one part missing from the documentation is you need to set your audio session.

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];

添加它,你会很高兴的.

Add that and you'll be good to go.

这篇关于iOS4进入后台播放音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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