Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an isPlaying() equivalent for SKAudioNode?

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?

like image 764
Mike Pandolfini Avatar asked Jan 18 '26 07:01

Mike Pandolfini


1 Answers

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)
like image 126
Knight0fDragon Avatar answered Jan 19 '26 23:01

Knight0fDragon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!