0

I'm playing a sound with the following code in a scene within a SpriteKit based app -

[self runAction:[SKAction playSoundFileNamed:@"mySound.mp3" waitForCompletion:NO]];

When I leave the scene and come back to it there is a crash as soon as it tries to play the sound.

I'm using ARC and know that if I don't play sounds the app is fine.

Interestingly enough if I loop through other scenes to get back to this one all works fine. But there's nothing that I'm doing in the code for moving back that's any different from that of moving forward.

Mark Reid
  • 2,611
  • 3
  • 23
  • 45

1 Answers1

3

I was able to fix this issue by creating a strong property for the sound action like this

@property (strong, nonatomic) SKAction *playMySound;

and initialised it like this

self.playMySound = [SKAction playSoundFileNamed:@"mySound.mp3" waitForCompletion:NO];

After that I had no more issues with the sound crashes. In addition it gave me a path for preloading them before they were played.

Mark Reid
  • 2,611
  • 3
  • 23
  • 45
  • Answer here: [link] (http://stackoverflow.com/questions/26683171/skaction-playsoundfilenamed-crashes-when-repeat-sprite-kit) – Daniel K Mar 16 '15 at 04:33
  • actions are copied by runAction: so the original is dropped as soon as it's created. – bshirley Mar 31 '15 at 17:19