SKAudioNode init(URL:) need help

I can't make a simple SKAudioNode test to work. Can somebody help. Here's what I trying to do:


Initialization:


let soundURL = NSURL(fileURLWithPath: NSBundle.mainBundle().pathForResource("TestSound", ofType: "caf")!)

soundNode = SKAudioNode(URL: soundURL)

soundNode.autoplayLooped = false

self.addChild(soundNode)


Then when running play action:


soundNode.runAction(SKAction.play())


It crashes at that point with EXC_BAD_ACCESS at thread point libAVFAudio.dylib`AVAudioFileImpl::CheckClientFormatSet:


The same TestSound.caf plays correctly with:

soundNode.runAction(SKAction.playSoundFileNamed("TestSound.caf", waitForCompletion: false))


What am I doing wrong?

Answered by Glabrain in 13044022

Continuing monologue.

My bad. You actually have to add the audio node to the scene and not a node in the scene. Still not able to achieve spatial sound effect.

Replying to myself,


If I init the node just as above and instead of running the action SKAction.play() I run the action SKAction.playSoundFileNamed("", waitForCompletion: false) i.e. leaving the name of the sound file empty it works. At least plays the sound. Have yet to test if it actually does the "3D" effects.

No 3D effect or any other change in sound no matter how far from the origin I place the sound node. Not exactly the expected or desired behavior, I guess.

Accepted Answer

Continuing monologue.

My bad. You actually have to add the audio node to the scene and not a node in the scene. Still not able to achieve spatial sound effect.

I had the same problem. I init the skaudionode in sks file, and relates to a wav file. If I run SKAction.play(), app crashes (bug?). So I have to run SKAction.playSoundFileNamed......


Besides, I don't get any 3d effect, bug in xcode beta?

SKAudioNode init(URL:) need help
 
 
Q