No matter what wav file I tried to play in an project, I keep getting the same error. The error states: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Resource namedfile.wav can not be loaded'
I cannot get any sound of any kind to load using SKAction.playSoundFilenamed. I have made sure that the file is names correctly and that doesn't seem to be the problem.
I have tested this in several projects, including the following test Game project wherein I use all default code except for a call to the SKAction
class GameScene: SKScene {
override func didMoveToView(view: SKView) {
/* 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));
let soundfile = SKAction.playSoundFileNamed("soundProject.wav", waitForCompletion: false)
runAction(soundfile)
self.addChild(myLabel)
}
I cannot get any sound of any kind to load using SKAction.playSoundFilenamed. I already checked to made sure that the file is named correctly and that it exits in the bundle. Any help would be greatly appreciated. Thank you
UPDATE I Ran my attached code on a different computer, and it compliled and ran perfectly. There must be something wrong with my xcode/simulator. Does anyone know how to reset it? Thanks
When you select your sound file in XCode, access the inspector on the right side, then make sure the file is selected for your target(s).
What color is your Sounds folder?
If it's blue, it means it's a Folder Reference.
If it's yellow, it's a Group.
You Choose Folder Reference -vs- Group when you import your folder.
I've found that SKAction.playSoundFilenamed functions correctly only when it's loaded as a Group (Yellow).
For me, this was the issue. Both of these compiled fine and gave no errors, but only the latter actually played the sound.
Did not work:
SKAction.playSoundFileNamed("combo.mp3", waitForCompletion: true)
Did work:
node.run(SKAction.playSoundFileNamed("combo.mp3", waitForCompletion: true))
Good luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With