先日、音声再生のプログラムを記述したのですが、音声が再生されません。ご指摘の程、よろしくお願いします。
import UIKit
import AVFoundation
class ViewController: UIViewController {
var player:AVAudioPlayer?
let sound_data = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("sample", ofType: "mp3")!)
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
do {
let player = try AVAudioPlayer(contentsOfURL: sound_data)
player.play()
}
catch let error as NSError {
print(error)
}
player?.prepareToPlay()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func play(sender: UIButton) {
player?.play()
}
@IBAction func pause(sender: UIButton) {
player?.pause()
}
@IBAction func stop(sender: UIButton) {
player?.stop()
player?.currentTime = 0
}
}