Created
October 25, 2015 05:23
-
-
Save loganwright/ebbe3c39958ec865c26d to your computer and use it in GitHub Desktop.
Sound File
This file contains hidden or 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
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