Reputation: 3823
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 ?
Upvotes: 10
Views: 1556
Reputation: 769
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
Upvotes: 1
Reputation: 1301
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!
Upvotes: 5
Reputation: 1147
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.
Upvotes: 2
Reputation: 51
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) }
Upvotes: 4