Sound mit dem AVAudioPlayer abspielen
Ich versuche einen Sound mit zu spielenAVAudioPlayer
aber es wird nicht funktionieren.
Bearbeiten 1: Funktioniert immer noch nicht.
Bearbeiten 2: Dieser Code funktioniert. Mein Gerät war im stillen Modus.
import UIKit
import AVFoundation
class ViewController: UIViewController {
var audioPlayer = AVAudioPlayer()
override func viewDidLoad() {
super.viewDidLoad()
var alertSound = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("button-09", ofType: "wav"))
println(alertSound)
var error:NSError?
audioPlayer = AVAudioPlayer(contentsOfURL: alertSound, error: &error)
audioPlayer.prepareToPlay()
audioPlayer.play()
}
}