watchOS cannot play audio file

I'm trying to play an audio file using WatchKit with no success. It plays well on the simulator but doesn't play on the real Watch.


I'm recording audio on the iPhone to .m4a and then use WKAudioFilePlayer or AVAudioPlayer or WKAudioFileQueuePlayer to play it. Neither of them works on the Watch.


For example the following code works on the simulator:


NSMutableArray<WKAudioFilePlayerItem *> *items = [NSMutableArray array];
WKAudioFileAsset *asset = [WKAudioFileAsset assetWithURL:[NSURL fileURLWithPath:fileName]]; // path to the .m4a file in Caches folder
WKAudioFilePlayerItem *item = [WKAudioFilePlayerItem playerItemWithAsset:asset];
[items addObject:item];
   
soundPlayer = [WKAudioFileQueuePlayer queuePlayerWithItems:items];
[soundPlayer play];


It outputs sound to the speakers on the computer. But it doesn't work on the real Watch with/without Bluetooth headphones. Apple music works on the headphones without a problem. I keep my file (fileName) in the Caches folder, might that be the case? Also does the .m4a format/bitrate matter?


Thanks!

In my case, I found that audio often does not work after you compile to the watch. Restart the watch to hear the audio.

Thank you for suggestion but it didn't help either 😟 Same result - works in simulator, doesn't work in the real Watch (watchOS 3.2).

The other possibilities is to test it under watchOS 4? After all this is going to be released soon.

The files have to be stored in shared container. It's in the WKAudioFilePlayer documention.


[[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:@"...

watchOS cannot play audio file
 
 
Q