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?

Accepted Reply

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
  • What is the status of this problem? My app freezes up (but eventually responds after a long hang time) upon entering the view containing the audio player, in simulator running iOS 12.4. My app works fine in simulators running iOS 15.4. This is a new problem for me after acquiring a new Mac running Monterey, or maybe to do with updating Xcode in conjunction with new Mac.

    How can I confirm that the problem doesn't exist in real devices? It is pretty difficult to program for multiple devices without the use of a proper simulator.

Add a Comment

Replies

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.
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
  • What is the status of this problem? My app freezes up (but eventually responds after a long hang time) upon entering the view containing the audio player, in simulator running iOS 12.4. My app works fine in simulators running iOS 15.4. This is a new problem for me after acquiring a new Mac running Monterey, or maybe to do with updating Xcode in conjunction with new Mac.

    How can I confirm that the problem doesn't exist in real devices? It is pretty difficult to program for multiple devices without the use of a proper simulator.

Add a Comment
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.