Created
January 12, 2015 20:31
-
-
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
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
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