Created
January 10, 2017 05:23
-
-
Save NikhilManapure/75b79d98195131f1a3a8bb756c494fa3 to your computer and use it in GitHub Desktop.
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 play(sound: String, ofType type: SoundExtension) { | |
if let soundID = notificationSoundLookupTable[sound] { | |
AudioServicesPlaySystemSound(soundID) | |
} else { | |
if let soundURL : CFURL = Bundle.main.url(forResource: sound, withExtension: type.rawValue) as CFURL? { | |
var soundID : SystemSoundID = 0 | |
let osStatus : OSStatus = AudioServicesCreateSystemSoundID(soundURL, &soundID) | |
if osStatus == kAudioServicesNoError { | |
AudioServicesPlaySystemSound(soundID); | |
notificationSoundLookupTable[sound] = (soundID) | |
}else{ | |
// This happens in exceptional cases | |
// Handle it with no sound or retry | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment