I am experimenting with other sound effect options for our game after determining SKAction.playSoundFileNamed is not only buggy and leaky but also creates a crash specifically during IAP interruptions (not OK, Apple). We are attempting to use SKAudioNodes, but the issue is we have overlapping sound effects. We would like to use a system whereby we have a queue of SKAudioNodes that exist with the identical effect: e.g. audioNode1, audioNode2, audioNode3, all with sound "fxmatch," and if audioNode1.isPlaying(), then we will move on in the queue to audioNode2, then audioNode3, etc. We have similar syntax already for AVAudioPlayer, where we check isPlaying(). Is there some method equivalent for SKAudioNodes?
Asked
Active
Viewed 149 times
1 Answers
1
if let playerNode = audioNode.avAudioNode as? AVAudioPlayerNode{
print(playerNode.isPlaying)
}
Or
extension SKAudioNode
{
var isPlaying : Bool { return (avAudioNode as? AVAudioPlayerNode)?.isPlaying ?? false }
}
...
print(audioNode.isPlaying)

Mike Pandolfini
- 532
- 4
- 17

Knight0fDragon
- 16,609
- 2
- 23
- 44
-
1Thanks as always. This is great, but will this only show isPlaying == false when I stop the node? I'm getting some odd behavior. In a small project it seems like once you play() isPlaying == true until you stop, so must I stop the SKAudioNodes manually when I am certain they are done playing? Note I have autoplaylooped = false. – Mike Pandolfini Jun 19 '19 at 20:43
-
1In my actual project behavior of this is erratic as well. The best way I can describe it is that it "sort of works" -- sometimes the SKAudioNodes will queue up multiple sounds, sometimes isPlaying() returns false after the sound plays and other times it will return true. – Mike Pandolfini Jun 19 '19 at 21:03
-
1https://stackoverflow.com/questions/44789866/is-avaudioplayernode-isplaying-flag-set-as-soon-as-schedulebuffer-is-called – Knight0fDragon Jun 20 '19 at 13:04