I recently followed this tutorial (https://www.youtube.com/watch?v=Y8A_Wkcx83Q) from Paul about playing sounds on watchkit using AVFoundation and AVAudioPlayer. It was very helpful, and I now have custom sounds playing on my own unique watchkit app!
Unfortunately, however, I am only able to hear these sounds play via the simulator on my computer. On my physical watch, no sound comes through.
To make matters even more confusing, different users who are testing my app via TestFlight seem to have different experiences with my custom sounds. Some (like me) can't hear them at all, some CAN hear them but only via bluetooth speakers, some can only hear them if their watch is not on silent mode, and others can only hear the sounds if their watch screen stays active.
In my app, I would like to be able to play a sound with a slight delayed start and have that sound play on the watch's external speaker regardless of whether the screen is asleep or not.
To accomplish this, I've tried adding background audio capabilities to both the iOS version and watchOS version of my app. I've also tried creating an AVAudioSession variable and tried adding the following lines of code before my AVAudioPlayer plays my actual sound:
do {
try audioSession.setCategory(AVAudioSessionCategoryPlayAndRecord, mode: AVAudioSessionPortBuiltInSpeaker,
routeSharingPolicy: AVAudioSessionRouteSharingPolicy.default, options: [])
} catch {
print("audiosession cannot be set")
}
do {
try audioSession.setActive(true) }
catch {
print ("audiosession cannot be activated")
}
However, I have still not accomplished any consistent playing of sound via the Apple Watch's speaker on a physical device. Thank you for your help!