Skip to content

Instantly share code, notes, and snippets.

@toast38coza
Created October 26, 2014 06:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toast38coza/56f40c05d14e23e56588 to your computer and use it in GitHub Desktop.
Save toast38coza/56f40c05d14e23e56588 to your computer and use it in GitHub Desktop.
Play Audio with swift
// requires linked AVFoundation.framework
// don't forget to import AVFoundation at the top of your controller
var player:AVAudioPlayer = AVAudioPlayer()
var error: NSError? = nil
var p1sounds = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("filenamegoeshere", ofType: "mp3")!)
player = AVAudioPlayer(contentsOfURL: p1sounds, error: &error)
player.play()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment