10

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 ?

salocinx
  • 3,715
  • 8
  • 61
  • 110
  • 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 Sep 16 '16 at 15:54
  • After ~50 fails it suddenly starts to work though. Same for you? – Fredrik Johansson Sep 16 '16 at 15:55
  • Have you try it on a real device or device simulator? – Alessandro Ornano Sep 16 '16 at 16:09
  • @Fredrik Johansson: Yes exactly the same, after several errors it begins to work normal. – salocinx Sep 16 '16 at 16:11
  • @Alessandro Ornano: On a real device (iPad Air). – salocinx Sep 16 '16 at 16:12
  • Real device (iPhone). I've also made sure that the sknode is not destroyed during the sound. Just to make sure... – Fredrik Johansson Sep 16 '16 at 16:16
  • Seems to be an other audio bug, otherwise it's not explainable why it's suddenly working after n-outputs... Isn't there any 3rd party library that handles audio correctly (including volume, pitch, etc.) ? – salocinx Sep 16 '16 at 16:21
  • Do you mind posting a bug report? – Fredrik Johansson Sep 16 '16 at 18:29
  • 1
    @Fredrik Johansson: Let me know if the problem persists and I will report it to Apple. – salocinx Sep 16 '16 at 20:20
  • I filed a straightforward bug report where I basically only referred to this thread. Better than nothing... – Fredrik Johansson Sep 17 '16 at 11:08
  • I also filed a bug report (28529295) but didn't get any reply yet. 3rd party audio libs like ObjectAL still work perfectly, but all the SpriteKit sound effects stopped working in all my SK-based games after updating to iOS10 :( – endavid Sep 29 '16 at 07:39
  • The problem came back... After running the app for some time, I suddenly get a lot of "SKAction: Error playing sound resource" errors. Very strange behaviour. – salocinx Sep 29 '16 at 10:46
  • same problem here ... – Hans Frankenstein Oct 08 '16 at 23:14
  • 1
    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 Oct 09 '16 at 10:11
  • I got another reply from Apple. Apparently they are still working on that bug, but they told me to keep checking the release notes of the updates. I check iOS 10.1 release notes but it doesn't mention anything relevant. Indeed, I updated my iPhone to 10.1 and the sounds still do not work. Release notes: https://support.apple.com/kb/DL1893?locale=en_US – endavid Oct 25 '16 at 20:11
  • Thanks for the update! I am currently working with ObjectAL. This is a really wonderful library working on all tested iOS versions and on all devices without a single problem. Lots of controls (pitch, pan, volume, etc.). Hopefully Apple does not stop support for OpenAL as long as they don't have any working substitute (there were rumours about kicking OpenAL out of the framework). – salocinx Oct 25 '16 at 20:18
  • It seems if I play a sound with waitForCompletion set to true, then all the sounds start working again, until I destroy the scene that preloaded the sounds. Then, I have to do the same trick, play a sound with waitForCompletion set to true, in order for the sound to work again. I can't test with iOS 10.1 because Apple messed up again and the latest stable Xcode 8.0 doesn't support iOS 10.1 ... T_T – endavid Nov 03 '16 at 23:49
  • 1
    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 Dec 10 '16 at 21:45

4 Answers4

5

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!

Fredrik Johansson
  • 1,301
  • 1
  • 13
  • 26
  • It reappeared. But much less frequent. Can it be that the problem is triggered if two sounds are loaded simultaneously? – Fredrik Johansson Sep 16 '16 at 20:00
  • Yes I did and now I have removed the pre-loading code. Works fine so far, without delays... – salocinx Sep 16 '16 at 20:06
  • I am using *.caf format, which is much smaller compared to the uncompressed *.wav format. Perhaps this triggers the delay? – salocinx Sep 16 '16 at 20:07
  • I changed to .caf, and now there's no delay. Don't know why really. The files are about the same size, but afinfo tells me that caf in optimized, and wav is not. That might be it. Thanks salocinx! – Fredrik Johansson Sep 17 '16 at 11:57
  • Ok, yes *.caf stands for CoreAudioFormat as far as I know. Seems somehow to be optimized for Apple devices and their audio frameworks... – salocinx Sep 17 '16 at 17:29
4

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) }
Jamal
  • 763
  • 7
  • 22
  • 32
2

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.

claassenApps
  • 1,137
  • 7
  • 14
1

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
Norman G
  • 759
  • 8
  • 18