Skip to content

Instantly share code, notes, and snippets.

@loganwright
Created October 25, 2015 05:23
Show Gist options
  • Save loganwright/ebbe3c39958ec865c26d to your computer and use it in GitHub Desktop.
Save loganwright/ebbe3c39958ec865c26d to your computer and use it in GitHub Desktop.
Sound File
import AVFoundation
protocol SoundFile {
var soundFile: String { get }
}
extension SoundFile {
private var nameComponents: [String] {
return soundFile.componentsSeparatedByString(".")
}
private var name: String {
return nameComponents.first!
}
private var type: String {
return nameComponents.last!
}
private var path: String {
return MainBundle.pathForResource(name, ofType: type)!
}
private var url: NSURL {
return NSURL.fileURLWithPath(path)
}
func play() {
var soundID: SystemSoundID = SystemSoundID(kSystemSoundID_Vibrate)
AudioServicesCreateSystemSoundID((url as CFURLRef), &soundID)
AudioServicesPlaySystemSound(soundID)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment