在iOS4的输入后台播放音频 [英] Entering background on iOS4 to play audio
问题描述
说起在后台播放音频时的文档,而写得不好。它使IM pression,所有你需要做的继续玩,你当前正在播放是只需添加一个键/值对的的info.plist音频
文件和wallah,它的神奇。
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.
然而,这并非如此。举例来说,如果我打一个MP3的2分钟之久,显然音频是足够长,能够发挥我打的home键我的应用程序发送到后台之后。问题是,即使我已经在我的的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 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屋!