我正在做一个教程,并且测试了这段代码,当我在模拟器上运行时,它可以工作,但是在iPhone上进行测试时,它不能。 我调试了,他没弄错,只是不播放声音。
import AVFoundation
class ViewController: UIViewController, AVAudioPlayerDelegate {
var audioPlayer = AVAudioPlayer()
@IBAction func notePressed(_ sender: UIButton) {
playSound(tag: sender.tag)
}
func playSound(tag: Int) {
let soundURL = Bundle.main.url(forResource: "note\(tag)", withExtension: "wav")
do {
audioPlayer = try AVAudioPlayer(contentsOf: soundURL!)
} catch {
print(error)
}
audioPlayer.numberOfLoops = -1
audioPlayer.prepareToPlay()
audioPlayer.play()
}
}
答案 0 :(得分:2)
播放音频之前,您必须先设置@Html.DropDownList("info", ViewBag.info, null, Model.info)