Klutch
Klutch

Reputation: 171

How do I enable background audio for an iPhone app

Currently I am designing an iOS application that will connect to a music stream through a network and play the audio to the user.

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.

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.

("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)

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?

Upvotes: 3

Views: 13304

Answers (3)

Dan Rosenstark
Dan Rosenstark

Reputation: 69777

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.

Upvotes: 3

TonyMkenu
TonyMkenu

Reputation: 7667

Look here an sample code 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/

Upvotes: 2

user2503864
user2503864

Reputation:

Just make an entry in plist

Application does not require background mode and set its value to 'NO' And add background Mode to VOIP

Upvotes: 1

Related Questions