Created
October 24, 2014 08:51
-
-
Save jchernan/de6c30b40fb69d03fb63 to your computer and use it in GitHub Desktop.
Sample usage of AVAudioSessionInterruptionNotification
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func addInterruptionNotification() { | |
// add audio session interruption notification | |
NSNotificationCenter.defaultCenter().addObserver(self, | |
selector: "handleInterruption:", | |
name: AVAudioSessionInterruptionNotification, | |
object: nil) | |
} | |
func handleInterruption(notification: NSNotification) { | |
if notification.name != AVAudioSessionInterruptionNotification | |
|| notification.userInfo == nil{ | |
return | |
} | |
var info = notification.userInfo! | |
var intValue: UInt = 0 | |
(info[AVAudioSessionInterruptionTypeKey] as NSValue).getValue(&intValue) | |
if let type = AVAudioSessionInterruptionType.fromRaw(intValue) { | |
switch type { | |
case .Began: | |
// interruption began | |
println("began") | |
case .Ended: | |
// interruption ended | |
println("ended") | |
} | |
} | |
} |
interruption end events are not guaranteed:
Note: There is no guarantee that a begin interruption will have a corresponding end interruption. Your app needs to be aware of a switch to a foreground running state or the user pressing a Play button. In either case, determine whether your app should reactivate its audio session.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It doesn't call on when interruption ends