Audio in ARKit causes a crash when returning from background

I have an ARKit app that plays sounds using playaudio
Code Block
let audioPlay = SCNAction.playAudio(audioSource!, waitForCompletion: false)

when the app moves to the background i get the following :
AURemoteIO.cpp:1590:Start: AUIOClientStartIO failed (561015905)
AVAEInternal.h:109  [AVAudioEngineGraph.mm:1544:Start: (err = PerformCommand(*ioNode, kAUStartIO, NULL, 0)): error 561015905

when it comes back to the foreground and a sound is played it crashes and i get the following:
[avae]      AVAEInternal.h:76  required condition is false: [AVAudioPlayerNode.mm:712:ScheduleBuffer: (
outputFormat.channelCount == buffer.format.channelCount)]

in crash logs the crash is happening here :
AVAudioFileImpl::CheckClientFormatSet() + 60


tried fixes:
  1. Enable background audio works but my app does not have any logical use for background audio

  2. self.sceneView.audioEngine.mainMixerNode.outputVolume = 0.0 when app moves to background. still crashes but less often

Any help would be appreciated.




Accepted Reply

Is there some solution about this issue?

I have tried to add following code to AppDelegate, it solves the issue but sounds continue playing when app runs in the background.

        let audioSession = AVAudioSession.sharedInstance()

        do {

            // Set the audio session category, mode, and options.

            try audioSession.setCategory(.playback, mode: .moviePlayback, options: [])

        } catch {

            print("Failed to set audio session category.")

        }

Replies

Sometimes this happens too
[aurioc]AURemoteIO.cpp:1086:Initialize: failed: 561015905 (enable 2, outf< 2 ch,   0 Hz, Float32, non-inter> inf< 2 ch,   0 Hz, Float32, non-inter>)
[aurioc] AURemoteIO.cpp:1086:Initialize: failed: 561015905 (enable 2, outf< 2 ch, 44100 Hz, Float32, non-inter> inf< 2 ch,   0 Hz, Float32, non-inter>)
[avae]      AVAEInternal.h:109  [AVAudioEngineGraph.mm:1344:Initialize: (err = PerformCommand(*outputNode, kAUInitialize, NULL, 0)): error 561015905


Is there some solution about this issue?

I have tried to add following code to AppDelegate, it solves the issue but sounds continue playing when app runs in the background.

        let audioSession = AVAudioSession.sharedInstance()

        do {

            // Set the audio session category, mode, and options.

            try audioSession.setCategory(.playback, mode: .moviePlayback, options: [])

        } catch {

            print("Failed to set audio session category.")

        }
this fixes the issue only if your app has a logical use for background audio