Multipeer Connectivity音频流停止在背景上工作 [英] Multipeer Connectivity audio streaming stop work on background

查看:209
本文介绍了Multipeer Connectivity音频流停止在背景上工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用iOS 7的 Multipeer Connectivity 框架进行一些音频流。流媒体效果很好,但当我把应用程序放在后台时,它就会停止工作。

I'm doing some audio streaming with iOS 7's Multipeer Connectivity framework. The streaming works well, but when I put the app on background it stops working.

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

Someone can tell me if this is a framework limitation, or I'm doing something wrong?


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

  • And, if it is a framework limitation, is it possible to do something to avoid this?

我可以使用后台任务,让流媒体和音乐在后台运行吗?

Can I use Background Tasks, to keep streaming and music working on background?

可以这样做吗?如果无法做到,那么iOS设备之间的 MultiPeer 音频流是否存在任何替代方案?

Is possible do this? If is not possible, do any alternatives exist for MultiPeer audio streaming between iOS devices?.

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

I´m using this example: https://github.com/tonyd256/TDAudioStreamer.

在此页面上解释: http://robots.thoughtbot.com/streaming-audio-to-multiple-listeners-via-ios-multipeer-connectivity

非常感谢!

推荐答案

用于播放音频的Apple文档背景(向下滚动一下)。一些相关的段落:

On the Apple documentation for playing audio in the background (scroll down a bit). Some relevant paragraphs:


当UIBackgroundModes键包含音频值时,系统的媒体框架会自动阻止相应的应用程序在移动时被暂停到后台。只要播放音频或视频内容或录制音频内容,该应用程序就会继续在后台运行。但是,如果录制或播放停止,系统将暂停该应用程序。

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播放音频,并保持你的应用程序不被暂停,只要你'已正确配置您的应用程序以在后台播放音频。

This means that iOS should recognize that you're playing audio through Core Audio, and keep your app unsuspended, as long as you've correctly configured your app for playing audio in the background.


由于您的应用在播放媒体文件时未被暂停,因此回调功能正常运行应用程序在后台。但是,在回调中,您应该只做提供播放数据所需的工作。例如,流式音频应用程序需要从其服务器下载音乐流数据并将当前音频样本推出以进行回放。应用程序不应执行与播放无关的任何无关任务。

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来接收音频数据并进行播放。

You should be able to operate normally as long as your app is still playing audio, and is allowed to do what it needs to in order to continue playing audio. This means that you should be able to continue to use MPC in the background to receive the audio data and play it.

请务必阅读有关该主题的完整文档,特别关于音频会话

Be sure to read the entire documentation on the subject, especially regarding Audio Sessions.

这篇关于Multipeer Connectivity音频流停止在背景上工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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