SKAction playsoundfilenamed fails to load sound

sc24evr picture sc24evr · Mar 3, 2015 · Viewed 9.9k times · Source

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

Answer

lchamp picture lchamp · Mar 3, 2015

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).

CaptureTarget