关于 iphone:Multipeer Connectivity 音频流停止在后台工作

Multipeer Connectivity audio streaming stop work on background

我正在使用 iOS 7 的 Multipeer Connectivity 框架进行一些音频流传输。流媒体运行良好,但当我将应用程序置于后台时,它停止工作。

有人可以告诉我这是框架限制,还是我做错了什么?

  • 而且,如果是框架限制,是否可以采取措施避免这种情况?

  • 我可以使用后台任务来保持流媒体和音乐在后台运行吗?

  • 可以这样做吗?如果不可能,iOS 设备之间的 MultiPeer 音频流是否存在任何替代方案?.

我正在使用这个例子:https://github.com/tonyd256/TDAudioStreamer.

在此页面上进行了说明:http://robots.thoughtbot.com/streaming-audio-to-multiple-listeners-via-ios-multipeer-connectivity。

非常感谢!


关于在后台播放音频的 Apple 文档(向下滚动一点)。一些相关段落:

When the UIBackgroundModes key contains the audio value, the system’s media frameworks automatically prevent the corresponding app from being suspended when it moves to the background. As long as it is playing audio or video content or recording audio content, the app continues to run in the background. However, if recording or playback stops, the system suspends the app.

You can use any of the system audio frameworks to work with background audio content, and the process for using those frameworks is unchanged.

这意味着,只要您正确配置了应用程序以在后台播放音频,iOS 就应该识别出您正在通过 Core Audio 播放音频,并保持您的应用程序未暂停。

Because your app is not suspended while playing media files, callbacks operate normally while your app is in the background. In your callbacks, though, you should do only the work necessary to provide data for playback. For example, a streaming audio app would need to download the music stream data from its server and push the current audio samples out for playback. Apps should not perform any extraneous tasks that are unrelated to playback.

只要您的应用仍在播放音频,您就应该能够正常运行,并且可以执行所需的操作以继续播放音频。这意味着您应该能够在后台继续使用 MPC 来接收并播放音频数据。

请务必阅读有关该主题的完整文档,尤其是有关音频会话的文档。


iOS 设备在被用户设置为后台时会因为明确的目的而获得有限的 cpu 周期。

根据Apple关于多任务和后台执行的文档,支持以下类型的应用程序,但必须明确声明:

  • 在后台向用户播放有声内容的应用程序,例如音乐播放器应用程序
  • 在后台录制音频内容的应用程序。
  • 让用户随时了解其位置的应用程序,例如导航应用程序
  • 支持互联网协议语音 (VoIP) 的应用程序
  • 需要定期下载和处理新内容的应用
  • 从外部配件接收定期更新的应用程序

您的案例属于Apps that play audible content to the user while in the background, such as a music player app。您可以从上面提供的链接中找到更多信息。