我有问题。按下按钮不会播放音乐。
import UIKit
import AVFoundation
class ViewController: UIViewController {
var player = AVAudioPlayer()
override func viewDidLoad() {
super.viewDidLoad()
do {
if let audioPath = Bundle.main.path(forResource: "Damage", ofType: "mp3") {
try player = AVAudioPlayer(contentsOf: URL(fileURLWithPath: audioPath))
}
} catch {
print("Error")
}
self.player.play()
}
@IBAction func playButton(_ sender: Any) {
self.player.play()
}
@IBAction func pauseButton(_ sender: Any) {
self.player.pause()
}
}