SKAudioNode in iOS9 and volume

I'm trying to use the new SKAudioNode in iOS9. I get the sound to play, but can't seemt to access the nodes volume?

Accepted Reply

Hi helloniklas,


The node's volume can be accesses via the AVAudioNode property and the related APIs or you can use the audio SKActions to set them.


[SKAction

+ play

+ pause

+ stop

+ changePlaybackRateTo:duration:

+ changePlaybackRateBy:duration:

+ changeVolumeTo:duration:

+ changeVolumeBy:duration:

+ changeObstructionTo:duration:

+ changeObstructionBy:duration:

+ changeOcclusionTo:duration:

+ changeOcclusionBy:duration:

+ changeReverbTo:duration:

+ changeReverbBy:duration:

+ stereoPanTo:duration:

]


Note that any action of the form somethingBySomething is a relative action, whereas somethignToSomething is an absolute action.


Cheers

Replies

Hi helloniklas,


The node's volume can be accesses via the AVAudioNode property and the related APIs or you can use the audio SKActions to set them.


[SKAction

+ play

+ pause

+ stop

+ changePlaybackRateTo:duration:

+ changePlaybackRateBy:duration:

+ changeVolumeTo:duration:

+ changeVolumeBy:duration:

+ changeObstructionTo:duration:

+ changeObstructionBy:duration:

+ changeOcclusionTo:duration:

+ changeOcclusionBy:duration:

+ changeReverbTo:duration:

+ changeReverbBy:duration:

+ stereoPanTo:duration:

]


Note that any action of the form somethingBySomething is a relative action, whereas somethignToSomething is an absolute action.


Cheers

Thanks for the answer. I did try the .avAudioNode but that dind't seem to work. Only way seemed to be doing avAudioNode.engine.mainMixernode.volume. But that had no effect. Using an action with 0 duration works though, thanks.


So, this won't work:

ballBounceSound.avAudioNode?.engine?.mainMixerNode.volume = Float(volume)


This will work:

ballBounceSound.runAction(SKAction.changeVolumeTo(Float(volume), duration: 0))

Ok. I've got the same problem but with SceneKit instead of SpriteKit. Any idea how I can solve it? Trying this:


player.audioNode?.engine?.mainMixerNode.volume = [FLOAT_VALUE]


does nothing. And I can't seem to find a similar "changeVolume" action in SceneKit.


Thanks!

Instead of mainMixerNode access volume like this: (audioNode.avAudioNode as? AVAudioPlayerNode)?.volume This is the correct way to get SKAudioNode's volume.