I am building an app that runs sound files from within the main bundle with a url. When I tested this on iOS 13, everything is fine. But with the new update of 13.1 I am getting an error here on the line of code
backgroundMusicPlayer = try AVAudioPlayer(contentsOf: URL(fileURLWithPath: sound!))
that says:
Thread 1: EXC_BAD_ACCESS (code=1, address=0x48
Here is the code that I am using in a custom class that runs background music when the app launches:
import Foundation
import AVFoundation
var backgroundMusicPlayer = AVAudioPlayer()
func playBackgroundMusic(filename: String){
let sound = Bundle.main.path(forResource: filename, ofType: "m4a")
do{
try
AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.playback, mode: AVAudioSession.Mode.default, options: [AVAudioSession.CategoryOptions.mixWithOthers])
backgroundMusicPlayer = try AVAudioPlayer(contentsOf: URL(fileURLWithPath: sound!))
}catch{
print (error)
}
backgroundMusicPlayer.numberOfLoops = -1
backgroundMusicPlayer.prepareToPlay()
backgroundMusicPlayer.play()
}
This all works fine in the simulator on iOS13, but crashes on a device running 13.1 It appears that the url is the issue, but I am not sure why. This same behavior happens on other screens where buttons are triggering audio files from the bundle.