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).
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.
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.
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.
Just go to the Music app on your device and tap on the pause (||) icon to stop playing music.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With