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") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
interruption end events are not guaranteed:
https://developer.apple.com/library/content/documentation/Audio/Conceptual/AudioSessionProgrammingGuide/HandlingAudioInterruptions/HandlingAudioInterruptions.html