0
오디오 플레이어에 문제가 있습니다. 내 viewcontroller 시작할 때 해당 URL에있는 nill 제공하고 어떻게 이것이 가능한지 전혀 몰라. 디버깅 할 시도하고 문제를 찾으려고하지만 난 아무 일도 일어나지 않습니다.AVAudioPlayer가 경로에 nill을 부여합니다. Swift 3 xcode 8.0
// VARS AUDIO
var sfxFive: AVAudioPlayer!
var sfxFour: AVAudioPlayer!
var sfxThree: AVAudioPlayer!
var sfxtwo: AVAudioPlayer!
var sfxOne: AVAudioPlayer!
var sfxGo: AVAudioPlayer!
override func viewDidLoad() {
super.viewDidLoad()
do {
let resourcePathFive = Bundle.main.path(forResource: "five", ofType: "m4a")!
let urlFive = URL(fileURLWithPath: resourcePathFive)
try sfxFive = AVAudioPlayer(contentsOf: urlFive)
let resourcePathFour = Bundle.main.path(forResource: "four", ofType: "m4a")!
let urlFour = URL(fileURLWithPath: resourcePathFour)
try sfxFour = AVAudioPlayer(contentsOf: urlFour)
let resourcePathThree = Bundle.main.path(forResource: "three", ofType: "m4a")!
let urlThree = URL(fileURLWithPath: resourcePathThree)
try sfxThree = AVAudioPlayer(contentsOf: urlThree)
let resourcePathTwo = Bundle.main.path(forResource: "two", ofType: "m4a")!
let urlTwo = URL(fileURLWithPath: resourcePathTwo)
try sfxtwo = AVAudioPlayer(contentsOf: urlTwo)
let resourcePathOne = Bundle.main.path(forResource: "one", ofType: "m4a")!
let urlOne = URL(fileURLWithPath: resourcePathOne)
try sfxOne = AVAudioPlayer(contentsOf: urlOne)
let resourcePathGo = Bundle.main.path(forResource: "go", ofType: "m4a")!
let urlGo = URL(fileURLWithPath: resourcePathGo)
try sfxGo = AVAudioPlayer(contentsOf: urlGo)
sfxFive.prepareToPlay()
sfxFour.prepareToPlay()
sfxThree.prepareToPlay()
sfxtwo.prepareToPlay()
sfxOne.prepareToPlay()
sfxGo.prepareToPlay()
} catch let err as NSError {
print(err.debugDescription)
}
}
func timerRunning() {
if timeElapsed == 5 {
sfxFive.play()
}else if timeElapsed == 4 {
sfxFour.play()
}else if timeElapsed == 3 {
sfxThree.play()
}else if timeElapsed == 2 {
sfxtwo.play()
}else if timeElapsed == 1 {
sfxOne.play()
}else if timeElapsed == 0 {
sfxGo.play()
}
}
오디오 파일을 루트 디렉토리에 있습니다 여기에
는 코드입니다.아무도 문제가 보이지 않습니까?
친절, 케빈.
대상의 빌드 단계를 확인하십시오. m4a 파일이 번들 자원 복사 단계 그룹에 나열되어 있지 않으면 추가하고 다시 정리하고 다시 실행하십시오. – Wolverine
지도 아래에 m4a 파일이 없습니다 –
해당 그룹에 추가하십시오. 프로젝트를 정리하고 다시 실행하십시오. – Wolverine