19

I encountered a problem when executing the following code on iOS 15. This occurs on both a simulator and a real device. In addition, this doesn't occur on iOS 14.

import AVFoundation

class MyAudio {
    let audioEngine: AVAudioEngine
    let audioFile: AVAudioFile
    let playerNode: AVAudioPlayerNode

    init() {
        audioFile = try! AVAudioFile(forReading: Bundle.main.url(forResource: "sound", withExtension: "mp3")!)
        audioEngine = AVAudioEngine()
        playerNode = AVAudioPlayerNode()
        audioEngine.attach(playerNode)
        audioEngine.connect(playerNode, to: audioEngine.mainMixerNode, format: audioFile.processingFormat)

        do {
            try audioEngine.start()
            playerNode.play()
        } catch {
            print(error.localizedDescription)
        }
    }
}

It will print these outputs.

2021-10-02 17:29:14.534934+0900 audio-sample-2021-10-02[11337:353838] throwing -10878
2021-10-02 17:29:14.537588+0900 audio-sample-2021-10-02[11337:353838] throwing -10878
2021-10-02 17:29:14.537895+0900 audio-sample-2021-10-02[11337:353838] throwing -10878
2021-10-02 17:29:14.538194+0900 audio-sample-2021-10-02[11337:353838] throwing -10878
2021-10-02 17:29:14.538512+0900 audio-sample-2021-10-02[11337:353838] throwing -10878
2021-10-02 17:29:14.538822+0900 audio-sample-2021-10-02[11337:353838] throwing -10878
2021-10-02 17:29:14.539127+0900 audio-sample-2021-10-02[11337:353838] throwing -10878
2021-10-02 17:29:14.539434+0900 audio-sample-2021-10-02[11337:353838] throwing -10878
2021-10-02 17:29:14.539789+0900 audio-sample-2021-10-02[11337:353838] throwing -10878

Although these errors occur, the sounds can be played without any crashes. However, it consumes a lot of time for initializing than usual. Is there any way for resolving this problem?

semisagi
  • 261
  • 2
  • 9
  • 1
    My app has this problem as well since iOS 15. It seems this error is thrown by AUComponent and means "kAudioUnitErr_InvalidParameter": https://johnnn.tech/q/getting-errors-when-running-ar-app-template-in-xcode/ I also have no initial crashes BUT my app also uses RealityKit which then complains that there is basically not enough performance for it to run properly, and I assume these two issues are connected. Very frustrating as I had no problems with iOS 14… :/ – Marc-André Weibezahn Oct 05 '21 at 16:29
  • Does this answer your question? [Getting "throwing -10878" when adding a source to a mixer](https://stackoverflow.com/questions/69206206/getting-throwing-10878-when-adding-a-source-to-a-mixer) – Nerdy Bunz Dec 20 '21 at 19:13
  • on macOS at least this is actually thrown at the attach(node) – Ryan Francesconi Mar 22 '22 at 17:56

1 Answers1

6

To fix this issue change to:

audioEngine.connect(playerNode, to: audioEngine.outputNode, format: audioFile.processingFormat)
Vitaliy69
  • 91
  • 4
  • 8
    Any idea why this works, and more importantly what do you do if you you actually want to connect multiple nodes to the mixer? – Andrew Madsen Dec 08 '21 at 05:19