I use this code to play audio:
let url = Bundle.main.url(forResource: "0", withExtension: "mp3")!
do {
audioPlayer = try AVAudioPlayer(contentsOf: url)
audioPlayer.delegate = self
audioPlayer.prepareToPlay()
play(sender:AnyObject.self as AnyObject)
} catch {
}
On iOS 12.4.1 on my iPhone X and iPhone 7 Plus this code work fine. But on iOS 13 and newer my app crashes on this line audioPlayer = try AVAudioPlayer(contentsOf: url)
with error Thread 1: EXC_BAD_ACCESS (code=1, address=0x48)
. But on my simulator iPhone 11 Pro Max with iOS 13 all works fine. Why is this happening and how to fix?