gpt4 book ai didi

ios - Swift ERROR : : Call can throw, 但未标记为 'try' 错误未处理

转载 作者:搜寻专家 更新时间:2023-10-31 21:53:25 25 4
gpt4 key购买 nike

<分区>

我刚开始学习 Swift,我想在我的代码中添加一首歌曲,以便在我按下按钮时播放它,但出现了该错误。如何解决这个错误?

var buttonAudioPlayer = AVAudioPlayer()

@IBAction func btnWarning(sender: UIButton) {
play()
}

override func viewDidLoad() {
super.viewDidLoad()
}

func play() {
let buttonAudioURL = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("warning", ofType: "mp3")!)
let one = 1

if one == 1 {
buttonAudioPlayer = AVAudioPlayer(contentsOfURL: buttonAudioURL) //getting the error in this line
buttonAudioPlayer.prepareToPlay()
buttonAudioPlayer.play()
}
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com