播放Apple Watch扬声器的声音

有没有办法播放Apple Watch扬声器的声音? 我一直无法在网上find任何文件。

现在可以使用WKAudioFilePlayerWKInterfaceMovie作为watchOS 2。

 NSURL *assetURL = [[NSBundle mainBundle] URLForResource:@"file" withExtension:@"wav"]; 

WKAudioFilePlayer示例:

 WKAudioFileAsset *asset = [WKAudioFileAsset assetWithURL:assetURL]; WKAudioFilePlayerItem *playerItem = [WKAudioFilePlayerItem playerItemWithAsset:asset]; WKAudioFilePlayer *audioFilePlayer = [WKAudioFilePlayer playerWithPlayerItem:playerItem]; [audioFilePlayer play]; 

WKInterfaceMovie示例:

 [self presentMediaPlayerControllerWithURL:assetURL options:nil completion:nil]; 

Apple Watch的扬声器无法播放声音,但是您可以触发播放iPhone上的声音文件,这里是关于它的线索

  • presentMediaPlayerControllerWithURL:options:completion:(watchOS 2.0中的新function)

url您要播放的媒体文件的url。 该URL必须指定一个文件; stream媒体不支持。 该文件可能包含audio,video或两者。

如果您为远程服务器上的文件指定URL,则此方法首先下载该文件,并显示一个显示操作进度的进度指示器。 由于WatchKit在从Web服务器下载文件时使用App Transport Security(ATS),因此该文件必须位于安全服务器上,且该URL必须使用httpsscheme。 如果您的服务器不支持ATS级安全性,请在播放之前自行下载该文件。

使用sharedcontainer,监视扩展名来存储文件。

使用此方法播放的任何audio都会路由到配对的蓝牙audio设备(如果有)。 如果没有蓝牙audio设备可用,则将audio路由到Apple Watch扬声器。

对于WatchOS3原始问题的答案是WKInterfaceInlineMovie https://developer.apple.com/reference/watchkit/wkinterfaceinlinemovie

你可以隐藏这个小部件,所以它不会改变你的界面devise。 如果没有连接蓝牙扬声器,它会通过手表的扬声器播放audio文件。