Using AVFoundation to play audio asset results in error

Hi, I've been trying to play an audio asset (.m4a) using an AVAudioPlayer, but results in what I believe is an internal error.

I've been using the following code to load and play the asset. Please note that the code was run using an iPad Pro 11-inch simulator with iPadOS 14 in Xcode 12 beta.

Code Block Swift
guard let audioData = NSDataAsset(name: "Example")?.data else {
    fatalError("Asset not found")
}
do {
    let audioPlayer = try AVAudioPlayer(data: audioData, fileTypeHint: "m4a")
    audioPlayer.play()
} catch {
    fatalError(error.localizedDescription)
}


The catch block is not reached, but the audio does not play and the console logs the following:

Code Block Text
2020-06-26 14:48:25.784066-0500 Name[45441:2235216]  HALB_IOBufferManager_Client::GetIOBuffer: the stream index is out of range
2020-06-26 14:48:25.784551-0500 Name[45441:2235216]  HALB_IOBufferManager_Client::GetIOBuffer: the stream index is out of range
2020-06-26 14:48:25.796707-0500 Name[45441:2235216] [aqme] 255: AQDefaultDevice (1): output stream 0: null buffer
2020-06-26 14:48:25.797137-0500 Name[45441:2235216] [aqme] 1778: EXCEPTION thrown (-50): error != 0


Can you please let me know if there's something wrong with the way I'm loading/playing the asset or if this looks like an internal bug in the betas?
Answered by Media Engineer in 616548022
Thank you bringing this to our attention. This is a known issue in the simulator and we are actively working to resolve it ASAP. 

Note that this issue is limited to the Simulator
I've performed the following test successfully in Xcode 11.5 with an iOS 13 simulator.

Code Block Swift
class ViewController: UIViewController {
    var audioPlayer: AVAudioPlayer!
    override func viewDidLoad() {
        super.viewDidLoad()
        guard let audioData = NSDataAsset(name: "Example")?.data else {
            fatalError("Asset not found")
        }
        do {
            self.audioPlayer = try AVAudioPlayer(data: audioData, fileTypeHint: "m4a")
            self.audioPlayer.play()
        } catch {
            fatalError(error.localizedDescription)
        }
    }
}


Sadly this same example does not work in iOS 14. I've filed a radar (FB7800041) about this.
Accepted Answer
Thank you bringing this to our attention. This is a known issue in the simulator and we are actively working to resolve it ASAP. 

Note that this issue is limited to the Simulator
Me too
It runs fine for me in Xcode 12 beta 3, but crashes in Xcode 11.6.
I don't know why the above is marked as a solution. Just because the media team is aware of it doesn't mean the problem is solved. This issue still exists 9 months later!
I'm currently having this problem in iOS simulators < 14 when using Big Sur. The behavior is also described in the reddit thread with ID jff05e.
Using AVFoundation to play audio asset results in error
 
 
Q