【发布时间】:2016-03-13 03:24:39
【问题描述】:
我正在关注 swift 1.0 的教程(意外),它展示了如何播放声音。现在在 swift 2.0 中它不会工作,请帮忙。
import UIKit
import AVFoundation
class ViewController: UIViewController {
var ButtonAudioURL = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("cow", ofType: "wav")!)
var ButtonAudioPlayer = AVAudioPlayer()
override func viewDidLoad() {
super.viewDidLoad()
ButtonAudioPlayer = AVAudioPlayer(contentsOfURL: ButtonAudioURL, error: nil)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func playAudio(sender: AnyObject) {
ButtonAudioPlayer.play();
}
@IBAction func Stop(sender: AnyObject) {
}
}
【问题讨论】:
标签: ios swift error-handling