Quick Description: App hangs up trying to play audio, enters loop spitting out data to console
First Fix Attempt: Download project and run that. Same issue.
Next: Added print logging to isolate problem, which looks to be this statement:
…
audioPlayer = try AVAudioPlayer(contentsOf: url)
…
When I comment out this statement, the app runs fine (if silent, with SFX print-logging). I suspect bad URL. Pertinent code from SoundManager class with print statements:
…
// get path to resource
print(soundFileName)
let bundlePath = Bundle.main.path(forResource: soundFileName, ofType: ".wav")
print(bundlePath!)
// check that it's not nil
guard bundlePath != nil else {
print(“nil exception triggered”)
return
}
let url = URL(fileURLWithPath: bundlePath!)
print(url)
do {
print (“enter do”)
// create the audio player
audioPlayer = try AVAudioPlayer(contentsOf: url)
print (“SFX:” + soundFileName)
// // play sfx
audioPlayer?.play()
}
catch {
print ("Couldn't create audio player.")
return
…
Console returns:
…
shuffle
/Users/oberon/Library/Developer/CoreSimulator/Devices/44DC320C-DD90-411D-8AE0-974AF684B819/data/Containers/Bundle/Application/E916DF5C-6338-42F8-8A89-6C3BC22F24D6/MatchGame2.app/shuffle.wav
file:///Users/oberon/Library/Developer/CoreSimulator/Devices/44DC320C-DD90-411D-8AE0-974AF684B819/data/Containers/Bundle/Application/E916DF5C-6338-42F8-8A89-6C3BC22F24D6/MatchGame2.app/shuffle.wav
enter do
2020-08-06 17:41:07.852212-0700 MatchGame2[5466:604450] HALCADClient::ConnectToServer: failed to find the AHS sub-server port, Error: 0x10000004
2020-08-06 17:41:12.854148-0700 MatchGame2[5466:604450] HALCADClient::ConnectToServer: failed to find the AHS sub-server port, Error: 0x10000004
2020-08-06 17:41:12.854554-0700 MatchGame2[5466:604450] HALDefaultDevice::Initialize: couldn’t add the default input device listener, Error: 268435460 (^P)
…
with last two messages repeating.
The path is what is weird. It is directing through the normally hidden Library folder and through the simulator instead of the direct file path. I think that’s the issue, but how do i solve it?
Thanks!