Is there an isPlaying() equivalent for SKAudioNode?

174 Views Asked by At

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?

1

There are 1 best solutions below

3
Knight0fDragon On
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)