Audio file cannot be played on watchOS after background

169 views Asked by At

When playing an audio file in watchOS (using SpriteKit):

run(SKAction.playSoundFileNamed("ready.wav", waitForCompletion:false))

It will works until you background the app (says face the watch outwards) and back, then the audio file cannot be played anymore.

I have tried many workarounds, including setting UIBackgroundModes to audio, but the sound will always stop working after the app is background and back. Any solution?

PS: I think I might have found the answer: use AVAudioPlayer instead of SKAction.

2

There are 2 answers

1
coolioxlr On

You need to start HKWorkoutSession and in info.plist enable workout background processing. Don't need the audio to play in background, just continue to play once it comes back from background.

0
Lim Thye Chean On

Use AVAudioPlayer instead of SKAction. This works.

Only SKAction.playSoundFileNamed has this issue.