Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SKAction playsoundfilenamed fails to load sound

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

like image 939
sc24evr Avatar asked Mar 03 '15 03:03

sc24evr


3 Answers

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

like image 52
lchamp Avatar answered Nov 16 '22 04:11

lchamp


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

like image 8
user3313360 Avatar answered Nov 16 '22 04:11

user3313360


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!

like image 3
Muindor Avatar answered Nov 16 '22 05:11

Muindor