Currently I am designing an iOS application that will connect to a music stream through a network and play the audio to the user.
目前我正在设计一个iOS应用程序,它将通过网络连接到音乐流,并向用户播放音频。
I have a simple setup with a button the enables the stream to start, and a UIwebview that connects to the stream. When I run the app (on an iPhone, NOT a simulator), the button works fine and launches the Quicktime player to begin playback for the audio. Pausing and playing from this screen works like a charm as well.
我有一个简单的设置,有一个按钮使流启动,以及一个连接到流的UIwebview。当我运行这个应用程序(在iPhone上,而不是在模拟器上)时,这个按钮运行良好,并启动Quicktime播放器开始播放音频。在这个屏幕上暂停和播放也很有魅力。
However I want my user to be able to start up the stream, turn the phone off (sleep the display) and continue to listen to the stream. However sleeping the display will fade out the audio until it stops playback.
然而,我希望我的用户能够启动流,关掉手机(睡眠显示),并继续收听流。然而,在停止播放之前,该显示器将会淡出音频。
I have tried to go into the app's PList file like a few others have told me to do online and added the field "Required background modes" and added App plays audio or streams audio/video using Airplay to the 0 array field and App downloads content from the network to the 1 array field.
我试图进入应用的PList文件像其他一些在线和添加的字段有告诉我“需要背景模式”和添加应用程序播放音频或流音频/视频使用Airplay 0阵列领域和应用下载内容从网络到1数组字段。
("App plays audio" was not offered through auto-complete even though that was the phrase told to make the stream work. Instead I left it as "App plays audio or streams audio/video using Airplay" before trying it the other way to little more luck)
(“应用程序播放音频”不是通过自动完成来提供的,尽管这个短语是用来让流媒体工作的。相反,我将它作为“应用程序使用Airplay播放音频或流音频/视频”而保留下来,然后再尝试另一种方式以获得更多的运气)
However neither of these are allowing the audio to continue to play when the display has been put to sleep. Can anyone offer up a suggestion as to how to make it work?
然而,当显示器处于休眠状态时,这两种方式都不允许音频继续播放。谁能提出一个建议,让它发挥作用?
3 个解决方案
#1
2
Look here an sample code https://github.com/jsagorin/iOSBackgroundAudio
这里有一个示例代码https://github.com/jsagorin/iOSBackgroundAudio。
and here .. some explanations (how to Set UIBackgroundModes key in app-info.plist file, Set Audio Session Category , etc) http://www.sagorin.org/ios-playing-audio-in-background-audio/
这里. .一些解释(如何在app-info中设置uibackgroundmode键)。plist文件,设置音频会话类别,等等)http://www.sagorin.org/ios-playingaudio -in- back地面-audio/。
#2
3
In Xcode 5.1, there's another place aside from the Plist that this needs to be set, Target -> Capabilities -> Background Modes... this seems to do more than just affect the plist, though I'm not absolutely sure of this.
在Xcode 5.1中,除了需要设置的Plist之外,还有另一个位置,目标->功能->后台模式…这似乎不仅仅影响了plist,尽管我不是很确定。
#3
1
Just make an entry in plist
在plist中做一个条目
Application does not require background mode and set its value to 'NO' And add background Mode to VOIP
应用程序不需要后台模式并将其值设置为“NO”,并向VOIP添加后台模式
#1
2
Look here an sample code https://github.com/jsagorin/iOSBackgroundAudio
这里有一个示例代码https://github.com/jsagorin/iOSBackgroundAudio。
and here .. some explanations (how to Set UIBackgroundModes key in app-info.plist file, Set Audio Session Category , etc) http://www.sagorin.org/ios-playing-audio-in-background-audio/
这里. .一些解释(如何在app-info中设置uibackgroundmode键)。plist文件,设置音频会话类别,等等)http://www.sagorin.org/ios-playingaudio -in- back地面-audio/。
#2
3
In Xcode 5.1, there's another place aside from the Plist that this needs to be set, Target -> Capabilities -> Background Modes... this seems to do more than just affect the plist, though I'm not absolutely sure of this.
在Xcode 5.1中,除了需要设置的Plist之外,还有另一个位置,目标->功能->后台模式…这似乎不仅仅影响了plist,尽管我不是很确定。
#3
1
Just make an entry in plist
在plist中做一个条目
Application does not require background mode and set its value to 'NO' And add background Mode to VOIP
应用程序不需要后台模式并将其值设置为“NO”,并向VOIP添加后台模式