I'm trying to build a WatchKit app that will give audio feedback during a workout. The audio is a series of short pre-recorded voice clips.
However, when the screen turns off - e.g. by starting a workout and then lowering the wrist - the audio doesn't play until the app becomes active again.
i.e.
I'm trying to figure out what I've missed in order to support audio in a workout app when the screen is off...
HKWorkoutSession
.WKBackgroundModes
UIBackgroundModes
.I've tried:
AVAudioPlayer
AVAudioEngine
+AVAudioPlayerNode
The behaviour is the same - as soon as the screen switches off, the sound no longer plays. The sound does play if the app is in the background and the screen is still on.
The app is running on Watch OS 4. I've tested on a Series 2 and a Series 3 watch and it is the same on both.
What have I missed?
Ahhh, finally I found this post and realised I had the same problem:
The AVAudioSession
category needs to be set to AVAudioSessionCategoryPlayback
(I had it set to ambient).
As soon as I changed the session category to AVAudioSessionCategoryPlayback it worked!