When applicationDidEnterBackground: triggers, I pause the audio which is playing using AVAudioPlayer:
[self.avPlayer pause];
Now, when applicationWillEnterForeground: triggers, the audio starts to play automatically! Since I didn't start the audio, the user interface is not updated and it shows that the audio is still in the paused state.
What's going on? This is happening in iOS 6.x, on iPad 2. This issue is not reproducing on the older iPad running iOS 5.x.
This is how I setup the AVAudioSession:
// Setup the audio session
BOOL succeeded = NO;
NSError *sessionError = nil;
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setDelegate:self];
if ([session respondsToSelector:@selector(setPreferredSampleRate:error:)]) {
succeeded = [session setPreferredSampleRate:128000.0f error:&sessionError];
} else {
succeeded = [session setPreferredHardwareSampleRate:128000.0f error:&sessionError];
}
succeeded = [session setCategory:AVAudioSessionCategorySoloAmbient error:&sessionError];
succeeded = [session setActive:YES error:&sessionError];