IPhone AudioStreamer doesn't work on background OS4 - iphone

I use Matt Galagher's AudioStreamer http://github.com/mattgallagher/AudioStreamer/ It works fine, however how to make in work at background on IPhone OS4?

Check out this document, in particular:
Applications that play audio can continue playing that audio while in the background. To indicate that your application plays background audio, include the UIBackgroundModes key to its Info.plist file. The value for this key is an array containing the audio string. When this key is present, the system’s audio frameworks automatically prevent your application from being suspended when it moves to the background. Your application continues to run in the background as long as it is playing audio. However, if this key is not present when the application moves to the background, or if your application stops playing audio while in the background, your application is suspended.
You can use any of the system audio frameworks to initiate the playback of background audio and the process for using those frameworks is unchanged. Because your application is not suspended while playing audio, the audio callbacks operate normally while your application is in the background. While running in the background, your application should limit itself to doing only the work necessary to provide audio data for playback. Thus, a streaming audio application would download any new data from its server and push the current audio samples out for playback.

Related

How to get AirPlay from UIWebView to continue playback when app is backgrounded *without* setting AVAudioSession category to Playback?

I've been attempting to make this work for quite a while now:
My app has the potential to play videos of Youtube from within UIWebView. The user could want to use AirPlay for this. When AirPlay is on, the device could go to sleep and normally video stops playing moments after that happens. As advised in other posts, I set the AVAudioSession category to the Playback one and it works - AirPlay continues even when the device display goes to sleep.
However, this has a side-effect; if the user has activated the app while music playback is on in the background, setting the app's audio session category to Playback causes the playing music to stop and this is definitely annoying.
Ideally, I want to set the AVAudioSession category when playback of Video starts, not when my App is activated - but I've not seen any central or UIWebview notification / delegate method to determine this.
I've got a hackish workaround for iPhone where the UIWebview hosted video player always loads full screen modal and thus can be determined. But my app is Universal and on iPad the video starts inline; I can't figure out a way to know when Video playback is going to happen. This is exactly the point when the audio category should be switched to Playback - it will actually help users who want background music playing only until video starts up.
I don't want to fool around with adding Javascript events on to Video tags inside the UIWebView - that seems too fragile to me.
Is it possible to observe any AVFoundation notifications that trigger for the UIWebView video playback? Or anyone know of any other way to determine if video playback will start / has started?

iOS - Access output audio from background program

Scenario: My app is running in the background. An iPhone/iPad user launches the iPod app (or Pandora or another program that plays audio) on their device and starts playing music. My app detects that that music is now playing, and records or in some way does things with the current playing audio (like stream it to a server), all while still running in the background.
Is this possible? Can anyone point me in the right direction in the SDK on how to do this?
You can't do this. And that is that.

iOS: allow user to choose whether audio will play in background or not

My app is able to play audio in the background. However, I'd like for it to not play audio in the background by default. I'd like to have a user preference which controls whether audio is played in the background or not.
Background audio is controlled via UIBackgroundModes info.plist. If I use this setting to allow background audio, my app will always play audio in the background. Is there a programmatic way to display playing audio in the background? Or do I need to do something less graceful, like fading audio in and out on my own when the app enters or leaves the background state?
Either depend on the Settings app, or provide the user a way in your app to set this preference, before your app is put in the background. Then continue to play or cut the sound depending on that setting, assuming you have set UIBackgroundModes to give your app the option.

Can a iPhone voice Recorder App always run in Background recording the Sounds and Play them?

Can a App record the Voice in the surroundings even when it runs in the background and play the recorded audio? Is it possible?
Multitasking doesn't allow audio recording to be in the background, so no.

AVAudioPlayer can play while iPhone screen is locked; can it record at that time too?

You can easily play sounds and record sounds using the high level AVAudioPlayer. And you can play sounds using the same framework, while the iPhone screen is locked. Can you record sounds at that time?
Yes, of course, just set correct category....................................................................................................................................
""AVAudioSessionCategoryRecord
For recording audio; this category silences playback audio. Recording continues with the screen locked.
Available in iPhone OS 3.0 and later.
Declared in AVAudioSession.h.
AVAudioSessionCategoryPlayAndRecord
For recording and playback of audio—simultaneous or not—such as for a VOIP (voice over IP) application.
This category silences audio from other applications, such as the iPod. You can, however, modify this category to allow mixing by using the kAudioSessionProperty_OverrideCategoryMixWithOthers property. Your audio continues with the Ring/Silent switch set to silent and with the screen locked.