Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sprite Kit: Why does playing sound return error?

I upgraded my Sprite Kit game to X-Code 8.0 and Swift 3 yesterday. Deployment target is currently set to iOS 9.3.

I play sound effects the following way:

self.run(SKAction.playSoundFileNamed("click.caf", waitForCompletion: false))

The sound effect is not played correctly (only about the half of the samples) and I get the following error (since upgrade to X-Code 8.0 and Swift 3):

SKAction: Error playing sound resource

Any ideas ?

like image 230
salocinx Avatar asked Sep 16 '16 15:09

salocinx


3 Answers

The problem disappeared when I removed this preload code. Do you have something similar? But now I get a short delay the first time a sound is played. Don't know how I shall handle that.

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  // Preload sounds
  [SKAction playSoundFileNamed:@"coinBlip.wav" waitForCompletion:NO];
  [SKAction playSoundFileNamed:@"bonus.wav" waitForCompletion:NO];
  :

My bug report (28350796) has been fixed now, and I've verified it on iOS 10.2 in beta simulator. So add a new bug report if your problems still exist on iOS 10.2!

like image 149
Fredrik Johansson Avatar answered Nov 12 '22 18:11

Fredrik Johansson


I found a solution that works with me. I use a computed SKAction sound property instead of preloaded sounds:

var enemyCollisionSound: SKAction { return SKAction.playSoundFileNamed("hitCatLady.wav", waitForCompletion: false) }
like image 4
YoussefMohamed Avatar answered Nov 12 '22 20:11

YoussefMohamed


I'm also having this issue and I've tracked it down to if a node is trying to play a sound and it has created an instance of another object within its code and that object has preloaded audio code, the node that created the other will not play its sounds.

like image 2
claassenApps Avatar answered Nov 12 '22 19:11

claassenApps