Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS4 - Background audio with iPhone Simulator

I unsuccessfully tried to implement a playback audio that continues to play in background by setting the UIBackgroundModes property and by activating an audio session as Joshua Weinberg suggested, but it doesn't work on the simulator and I have no chance to test on a device with iOS4. I read about of a possible issue with the simulator, is it likely? Is there anyone who has produced code that works on the simulator? Thanks and sorry because I originally posted it as answer (since no "add comment" link was enabled).

like image 324
qfwfq Avatar asked Jul 08 '10 13:07

qfwfq


People also ask

How do I play music in the background on my iPhone?

Go to Settings > Accessibility > Audio/Visual > Background Sounds, then turn on Background Sounds. Set any of the following: Sound: Choose a sound; the audio file downloads to your iPhone.

What is background audio mode?

During background monitoring, the video and audio are not transmitted, which helps to save your battery on the Person Station device. You'll also be able to use other audio apps (e.g., music and video players). To use the background mode, make sure to enable notifications on your Person Station's device.

What is audio playback on iPhone?

When your app plays audio, it silences any other background audio. It supports audio playback, but disallows audio recording (audio recording isn't supported in tvOS). In iOS, setting the Ring/Silent switch to silent mode silences your app's audio. In iOS, locking the device silences the app's audio.

How do I turn off background music on my iPhone?

Just go to the Music app on your device and tap on the pause (||) icon to stop playing music.


1 Answers

voidness,

It is working for me by implementing this code. This will not work in the simulator though for whatever reason. So if your code is the same or similar, have faith that it does work brilliantly on my iPod Touch with iOS4 installed.

App Delegate.m (either in init or applicationDidFinishLaunching)

- (id) init {   

    // allows you to play in the background when app is suspended in iOS4
    [[AVAudioSession sharedInstance] setDelegate: self];
    [[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error:nil];

}

And of course be sure to set the UIBackgroundModes key to audio like was stated before.

Best of luck,

Rob

like image 95
iwasrobbed Avatar answered Sep 28 '22 10:09

iwasrobbed