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。
非常感谢!
- 关于这个主题的任何更新?您的应用在审核期间被拒绝了吗?我阅读了至少一个示例应用程序,该应用程序将音频流式传输到多个 iOS 设备并从 App Store 中删除。
- 我使用了 TDAudioStreamer,但它不播放音频,它只是显示歌曲文件的图像和信息。你能建议我你是如何实施的吗?
关于在后台播放音频的 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 来接收并播放音频数据。
请务必阅读有关该主题的完整文档,尤其是有关音频会话的文档。
- 你有所有的理由,真的谢谢!嗯,我需要等待 19 个小时才能带来你的积分:D!
- 这在 2019 年仍然准确吗?我的理解是,如果没有 UIBackgroundModes 中的”voip”键,网络活动(使用 MultipeerConnectivity)可能会在后台操作约 10 分钟后被阻止。
iOS 设备在被用户设置为后台时会因为明确的目的而获得有限的 cpu 周期。
根据Apple关于多任务和后台执行的文档,支持以下类型的应用程序,但必须明确声明:
- 在后台向用户播放有声内容的应用程序,例如音乐播放器应用程序
- 在后台录制音频内容的应用程序。
- 让用户随时了解其位置的应用程序,例如导航应用程序
- 支持互联网协议语音 (VoIP) 的应用程序
- 需要定期下载和处理新内容的应用
- 从外部配件接收定期更新的应用程序
您的案例属于Apps that play audible content to the user while in the background, such as a music player app。您可以从上面提供的链接中找到更多信息。
- 您描述的后台模式是通过网络进行后台下载以保持数据最新。它不适用于多点流媒体之类的东西。这只会每隔几个小时调用一次,以使应用程序中的内容保持最新,不定期且由 iOS 系统本身
- 谢谢,但如果 MultiPeer Connectivity 框架无法实现,我还能做什么?同时将音乐流式传输到多个设备还有其他替代方案吗?我读了很多,但我找不到正确的方法。
- 数据是否总是来自一台设备?
- 这个想法是为连接到多对等会话的任何设备生成数据,但是如果您知道从一台设备执行此操作的一种方法,无论如何,这对我很有用。
- 好吧,如果您可以仅源自一台设备,那么您可以在”主机”设备上使用网络服务器。否则,我认为你可能对 MPC 不走运。您可以尝试使用音频背景模式,但您的应用似乎没有落入涵盖的用例(本地、URL、Airplay)中。不过,它值得一试。
- 是的,我正在考虑设备上的网络服务器选项(CocoaHTTPServer),并通过 http 或类似的方式传输数据,但我需要为此生成一个本地主机? ,我正在阅读这个,但在一些苹果文档中,说从代码中执行此操作是不可能的,并且这种方式会消耗大量电池,我想这样做的唯一方法是由用户手动执行。你怎么看?
- Standby :D Joel 的答案不应该让你放弃大部分工作。
来源:https://www.codenong.com/21856978/
