0
버튼이 사운드를 재생하지 않고 ??버튼이 사운드를 재생하지 않습니다. wav 파일을 포함 시켰습니다. 어떻게하면 더 정확한 코딩을 할 수 있습니까?
import UIKit
import AVFoundation
//var audioPlayer: AVAudioPlayer!
class ViewController: UIViewController {
var audioPlayer: AVAudioPlayer!
override func viewDidLoad() {
super.viewDidLoad()
let path = Bundle.main.path(forResource: "BtnSon", ofType: " WAV")
let soundURL = URL(fileURLWithPath: (path)!)
do {
try audioPlayer = AVAudioPlayer(contentsOf: soundURL)
audioPlayer.prepareToPlay()
} catch let err as NSError {
print(err.debugDescription)
}
}
@IBAction func numberPressed(Sender: UIButton){
playSound()
}
func playSound(){
if audioPlayer.isPlaying {
audioPlayer.stop()
}
audioPlayer.play()
}
}
동일합니다. 치명적인 오류 : 예기치 않게 찾지 못했습니다. 선택 값을 래핑하지 않았습니다. (lldb) –
"wav"유형을 사용하고 있으며 선행 공백없이 "wav"를 시도합니다. –