import UIKit
import AVFoundation

class ViewController: UIViewController{

    var btnSound: AVAudioPlayer!
    override func viewDidLoad() {
        super.viewDidLoad()
        let path = NSBundle.mainBundle().pathForResource("btn", ofType: "wav")
        let soundUrl = NSURL(fileURLWithPath: path!)

        do {
            try btnSound = AVAudioPlayer(contentsOfURL: soundUrl)
            btnSound.prepareToPlay()
        } catch {

        }
    }
    ...

Reference: How to play sounds using AVAudioPlayer

results matching ""

    No results matching ""