1
我每次按 a button
時都會得到一個Thread1:EXC_BAD_ACCESS(code=1, address = 0X48)
。我檢查了我的連接,我的mp3文件「歌曲」是正確的。我不確定有什麼問題。我的按鈕工作得很好,但它只是AVAudioPlayer (var Player)
,它不允許按鈕崩潰程序並返回錯誤。任何幫助將不勝感激(我是Swift的初學者)。Thread1:EXC_BAD_ACCESS(code = 1,address = 0X48)AVAudioPlayer(Swift)
import UIKit
import AVFoundation
class ViewController: UIViewController {
var player:AVAudioPlayer = AVAudioPlayer()
@IBAction func play(_ sender: UIButton) {
player.play()
}
@IBAction func pause(_ sender: UIButton) {
player.pause()
}
@IBAction func replay(_ sender: UIButton) {
player.currentTime = 0
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
do{
let audioPath = Bundle.main.path(forResource: "song", ofType: "mp3")
try player = AVAudioPlayer(contentsOf: NSURL(fileURLWithPath: audioPath!) as URL)
}
catch{
//error
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
是的,我檢查了我的連接。我不確定player.play()有什麼問題 – Edward