Hi 👋! We have a SpriteKit-based app where we play AVAudio
sounds in three different ways:
- Effects (incl. UI sounds) with
AVAudioPlayer.
- Long looping tracks with
AVAudioPlayer.
- Short animation effects on the timeline of SpriteKit's
SKScene
files (effectivelySKAudioNode
nodes).
We've found that when you exit the app or otherwise interrupt audio plays, future audio plays often fail. For example, there's a WebKit-based video trailer inside the app, and if you play it, our looping background music track (2.) will stop playing, and won't resume as you close the trailer (return from WebKit). This is probably due to us not manually restarting the track (so may well be easily fixed). Periodically played AVAudioPlayer audio (1.) are not affected.
However, the more concerning thing is that the audio tracks on SKScene
file timelines (3.) will no longer play. My hypothesis is that AVAudioEngine
gets interrupted, and needs to be restarted for those AVAudioNode
elements to regain functionality. Thing is, we don't deal with AVAudioEngine
at all currently in the app, meaning it is never initiated to begin with.
Obviously things return to normal when you remove the app from short-term memory and restart it. However, it seems many of our users aren't doing this, and often report audio failing presumably due to some interruption in the past without the app ever being cleared from memory.
Any idea why timeline-run SKAudioNodes would fail like this? Should the app react to app backgrounding/foregrounding regarding audio?
Any help would be very much appreciated ✌️!