10
votes

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 ?

4
I see exactly the same problem. I was going to write a post here. I tried to play a wav like this [SKAction playSoundFileNamed:@"throw.wav" waitForCompletion:NO]. It has worked before on Xcode7/iOS9. - Fredrik Johansson
After ~50 fails it suddenly starts to work though. Same for you? - Fredrik Johansson
@Fredrik Johansson: Let me know if the problem persists and I will report it to Apple. - salocinx
My bug report was closed as "Duplicate", but the duplicate bug is still "Open". I can't check the description of the duplicate since I didn't report it... Apart from that, not a single word from Apple :( - endavid
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! - Fredrik Johansson

4 Answers

5
votes

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!

4
votes

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) }
2
votes

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.

1
votes

Having had the same issue, getting an error “SKAction: Error playing sound resource” the first time certain sounds are played, I found that assigning the sound’s SKAction to an empty variable in “didMoveToView” completely solved the issue for me.

Declare the sound action in the normal simplest way:

let waterDropSoundAction = SKAction.playSoundFileNamed("WaterDrop.caf", waitForCompletion: false)

Then to load the sound action without actually playing it in didMoveToView:

let _ = waterDropSoundAction