Skip to content

Instantly share code, notes, and snippets.

@pfeilbr
Created January 12, 2015 20:31
Show Gist options
  • Save pfeilbr/04c9970cd14a06fdddfc to your computer and use it in GitHub Desktop.
Save pfeilbr/04c9970cd14a06fdddfc to your computer and use it in GitHub Desktop.
example of loading and laying sound files (.wav) from directory in app bundle
import AudioToolbox
func loadAndPlaySounds() {
var path = NSBundle.mainBundle().bundlePath.stringByAppendingPathComponent("sounds")
if let fileNames = NSFileManager.defaultManager().contentsOfDirectoryAtPath(path, error: nil) as? [String] {
for fileName in fileNames {
var filePath = path.stringByAppendingPathComponent(fileName)
println("filePath = \(filePath)")
let soundURL = NSURL(fileURLWithPath: filePath)
var mySound: SystemSoundID = 0
AudioServicesCreateSystemSoundID(soundURL, &mySound)
AudioServicesPlaySystemSound(mySound)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment