.playSoundFileNamed leads crash NSException

Hey, when i try to run sound action with sprite kit it crashes even at sprite kit's default template as you see below. I tried directly adding self.runAction(SKAction.playSoundFileNamed("bounce.mp3", waitForCompletion: false) to touchesbegan too but it crashes when i click this time.


I think it crashes when its trying to declare play sound action to memory. Its like it cant get my audio file. It says libc++abi.dylib: terminating with uncaught exception of type NSException. Im a C++ programmer and this is my first app with swift and sprite kit. Any help will be very very appreciated.






import SpriteKit


class GameScene: SKScene {



var bouncesound = SKAction()



override func didMoveToView(view: SKView) {

bouncesound = SKAction.playSoundFileNamed("bounce.mp3", waitForCompletion: false)

/ Setup your scene here */

let myLabel = SKLabelNode(fontNamed:"Chalkduster")

myLabel.text = "Hello, World!";

myLabel.fontSize = 65;

myLabel.position = CGPoint(x:CGRectGetMidX(self.frame), y:CGRectGetMidY(self.frame));

self.addChild(myLabel)

}


override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {

/ Called when a touch begins */

for touch in (touches as! Set<UITouch>) {

let location = touch.locationInNode(self)

let sprite = SKSpriteNode(imageNamed:"Spaceship")

sprite.xScale = 0.5

sprite.yScale = 0.5

sprite.position = location

let action = SKAction.rotateByAngle(CGFloat(M_PI), duration:1)

sprite.runAction(SKAction.repeatActionForever(action))

self.addChild(sprite)

self.runAction(bouncesound)

}

}


override func update(currentTime: CFTimeInterval) {

/ Called before each frame is rendered */

}

}

Creating a sample project, adding the lines you've shown above, run it. And I get the following waring message, not an app crash like you described.

(I changed `var bouncesound = SKAction()` to `var bouncesound: SKAction!`, but this wouldn't affect.)

2015-08-18 06:32:41.635 MyPlaySoundFileNamed[35716:4091711] SKAction: Error loading sound resource: "bounce.mp3"


And after I added the downloaded free "bounde.mp3" file to the project, the app plays the sound for every touch.


So, this is just my guess, your "bounce.mp3" may be too big or mal-formed.

.playSoundFileNamed leads crash NSException
 
 
Q