0
@IBAction func sound1(sender: UIButton)
{
var sound = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("Sound1", ofType: "wav")!)
do {
try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
} catch _ {
}
do {
try AVAudioSession.sharedInstance().setActive(true)
} catch _ {
}
var error: NSError?
do {
audioPlayer = try AVAudioPlayer(contentsOfURL: sound)
} catch var error1 as NSError {
error = error1
audioPlayer = nil
}
audioPlayer.prepareToPlay()
audioPlayer.volume = 1
audioPlayer.play()
}
這是當前的代碼,我這個項目更新到斯威夫特2
audioPlayer = nil
試圖運行應用程序時,我得到這個問題之前,有是這樣的:
不能鍵入「NilLiteralConvertible」的值賦給類型的值「AVAudioPlayer」