Check if node already attached to AVAudioEngine

832 Views Asked by At

I successfully attach AVAudioPlayer nodes to my AVAudioEngine. However, I need to later check if these nodes have already been attached to it (so I don't re-add them).

Is there any certain property on the engine that I can check to see if its already been attached?

2

There are 2 best solutions below

2
On

The implementation more than likely uses an interface implementation and has an API associated with it. I would suggest reading the API to check if a function exists that returns a list of (active) nodes attached.

1
On

You could check the engine property of the AVAudioPlayerNode and if nil this means it is not attached to an audio engine.

for playerNode in yourPlayerNodeArray {
        if playerNode.engine == nil {
            yourEngine.attach(playerNode)
        }
    }