Question

Here's what currently happens in my app:

Locking: iPhone Lock Button Pressed -> Audio Paused
Unlocking: iPhoneUnlocked Button Pressed -> Audio Resumed -> Slide to Unlock -> App Appears

I want the Unlocking sequence to be:

Unlocking: iPhoneUnlock Button Pressed -> Slide to Unlock -> Audio Resumed -> App Appears

I am using OS 2.2.1 and AVFoundation Framework, and here's what I have already tried:

  • I tried to use applicationWillResignActive and applicationDidBecomeActive callbacks of the AppDelegate, it doesn't work. Although applicationDidBecomeActive is called at the correct time (i.e. when user has slided to unlock the device), the audio gets resumed as soon as unlock button is pressed (I guess it is because of the audio sessions), so I tried:

  • I implemented audioPlayerBeginInterruption and audioPlayerEndInterruption selectors of the AVAudioPlayerDelegate, it looks like these methods never get called (I have placed log calls). I'm sure I am setting the delegate properly since audioPlayerDidFinishPlaying is correctly called when an audio file has finished playing.

P.S: I am testing on device if that wasn't obvious

Was it helpful?

Solution

They apparently only get called when an Audio session was interrupted, that's to say if you were playing audio and it is being interrupted by other audio which requests an active session. In short: they dont get called when the phone becomes inactive, but they get called when you receive a call for example. But even then they only get called when the AVAudioplayer was active at the time. I'm still wrestling with that crappy system...

OTHER TIPS

Slight abuse of the system, but you can observe the file protection notifications to find out when the device was unlocked. You could use that to decide when to play the audio again.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top