3

I've been reading some posts regarding playing sounds in an Apple Watch and it looks it is not possible... However, such posts deals with audio files, and I'd like to know if it would be possible to play at least system sounds, and if notifications delivered to the watch could play a system sound like notifications in iPhone and iPad can. I don't find anything related to sounds neither in Apple Watch Human Interface Guidelines, nor in Apple Watch Programming Guide.

Thanks

AppsDev
  • 12,319
  • 23
  • 93
  • 186

3 Answers3

3

It's not possible to play any audio by using the WatchKit API.

Jordi Bruin
  • 1,588
  • 1
  • 11
  • 20
  • 1
    Jordi is correct, this is not possible with the current implementation of WatchKit. You can only play audio from the iOS app. – cnoon Mar 03 '15 at 16:43
1

You can load your audio file or system sound and play it with your Apple Watch speaker. Using WKAudioFilePlayer for playing audio file required bluetooth headphones connected to your Apple Watch to play the sound.

To play any of the few haptic feedback sounds with vibration using WKInterfaceDevice:

[[WKInterfaceDevice currentDevice] playHaptic:WKHapticTypeFailure] 

To play any audio file, use AVAudioEngine:

1) Add AVFoundation.framework to your Frameworks list.

2) In .h file, put

#import <AVFoundation/AVFoundation.h>

@property (nonatomic) AVAudioEngine *audioEngine;
@property (nonatomic) AVAudioPlayerNode *playerNode;
@property (nonatomic) AVAudioFile *audioFile;
@property (nonatomic) AVAudioPCMBuffer *audioPCMBuffer;

3) In .m file, put

NSError *error = nil;
NSURL *fileURL = [[NSBundle mainBundle] URLForResource:@"alarm" withExtension:@"wav"];
self.audioFile = [[AVAudioFile alloc] initForReading:fileURL error:&error];
if (error) {
    NSLog(@"error");
    return;
}

self.audioEngine = [[AVAudioEngine alloc]init];

AVAudioFormat *audioFormat = self.audioFile.processingFormat;
AVAudioFrameCount length = (AVAudioFrameCount)self.audioFile.length;
self.audioPCMBuffer = [[AVAudioPCMBuffer alloc] initWithPCMFormat:audioFormat frameCapacity:length];
[self.audioFile readIntoBuffer:self.audioPCMBuffer error:nil];


AVAudioMixerNode *mixerNode = [self.audioEngine mainMixerNode];
self.playerNode = [[AVAudioPlayerNode alloc] init];
[self.audioEngine attachNode:self.playerNode];
[self.audioEngine connect:self.playerNode to:mixerNode format:self.audioFile.processingFormat];

[self.audioEngine startAndReturnError:&error];
[self.playerNode scheduleFile:self.audioFile atTime:nil completionHandler:nil];
[self.playerNode play];

You can use these classes from watchOS 2.0 further. There is a documentation for playHaptic: and AVAudioEngine classes.

I hope this will help you to solve your problem.

martinkabat
  • 63
  • 1
  • 9
0

In watchOS 2 this is now possible. Due to the NDA I can't elaborate more. Please review developer documentation Apple has provided.

donkey
  • 1,343
  • 13
  • 32