Question

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?

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

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

Explained on this page: http://robots.thoughtbot.com/streaming-audio-to-multiple-listeners-via-ios-multipeer-connectivity.

Thanks a lot!

Was it helpful?

Solution

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

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.

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.

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.

OTHER TIPS

iOS devices get limited cpu cycles for explicit purposes when they have been backgrounded by the user.

According to Apple's documentation on multitasking and execution in the background, the following types of apps are supported, but have to be explicitly declared:

  • Apps that play audible content to the user while in the background, such as a music player app
  • Apps that record audio content while in the background.
  • Apps that keep users informed of their location at all times, such as a navigation app
  • Apps that support Voice over Internet Protocol (VoIP)
  • Apps that need to download and process new content regularly
  • Apps that receive regular updates from external accessories

Your case falls under Apps that play audible content to the user while in the background, such as a music player app. You can find more information from the link provided above.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top