播放Apple Watch扬声器的声音

时间:2022-01-07 18:59:08

Is there a way to play sound out of the Apple Watch's speaker? I have been unable to find any documentation online.

有没有办法从Apple Watch的扬声器中播放声音?我无法在线找到任何文档。

4 个解决方案

#1


17  

This is now possible as of watchOS 2 using WKAudioFilePlayer or WKInterfaceMovie.

现在可以使用WKAudioFilePlayer或WKInterfaceMovie从watchOS 2开始。

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

WKAudioFilePlayer example:

WKAudioFilePlayer示例:

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

WKInterfaceMovie example:

WKInterfaceMovie示例:

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

#2


4  

It is not possible to play sound out of the Apple Watch's speaker, but you can trigger playing a sound file on the iPhone, here is thread about it

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

#3


3  

For WatchOS3 the answer to the original question is WKInterfaceInlineMovie https://developer.apple.com/reference/watchkit/wkinterfaceinlinemovie

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

You can hide the widget so it does not alter your interface design. It plays audio files through the watch's speaker if no bluetooth speaker is connected.

您可以隐藏窗口小部件,使其不会改变您的界面设计。如果没有连接蓝牙音箱,它会通过手表的扬声器播放音频文件。

#4


2  

  • presentMediaPlayerControllerWithURL:options:completion: (New in watchOS 2.0)
  • presentMediaPlayerControllerWithURL:options:completion :( watchOS 2.0中的新增功能)

URL The URL of the media file you want to play. The URL must specify a file; streamed media is not supported. The file may contain audio, video, or both.

URL您要播放的媒体文件的URL。 URL必须指定一个文件;不支持流媒体。该文件可能包含音频,视频或两者。

If you specify a URL for a file on a remote server, this method downloads the file first and displays a progress indicator showing the progress of the operation. Because WatchKit uses App Transport Security (ATS) when downloading files from a web server, the file must be on a secure server, and the URL must use the https scheme. If your server does not support ATS–level security, download the file yourself before playing it.

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

Use sharedcontainer, watch extensions, for storing the file.

使用sharedcontainer,watch extensions来存储文件。

Any audio you play using this method is routed to a paired Bluetooth audio device if one is available. If no Bluetooth audio device is available, audio is routed to to the Apple Watch speaker.

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

#1


17  

This is now possible as of watchOS 2 using WKAudioFilePlayer or WKInterfaceMovie.

现在可以使用WKAudioFilePlayer或WKInterfaceMovie从watchOS 2开始。

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

WKAudioFilePlayer example:

WKAudioFilePlayer示例:

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

WKInterfaceMovie example:

WKInterfaceMovie示例:

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

#2


4  

It is not possible to play sound out of the Apple Watch's speaker, but you can trigger playing a sound file on the iPhone, here is thread about it

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

#3


3  

For WatchOS3 the answer to the original question is WKInterfaceInlineMovie https://developer.apple.com/reference/watchkit/wkinterfaceinlinemovie

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

You can hide the widget so it does not alter your interface design. It plays audio files through the watch's speaker if no bluetooth speaker is connected.

您可以隐藏窗口小部件,使其不会改变您的界面设计。如果没有连接蓝牙音箱,它会通过手表的扬声器播放音频文件。

#4


2  

  • presentMediaPlayerControllerWithURL:options:completion: (New in watchOS 2.0)
  • presentMediaPlayerControllerWithURL:options:completion :( watchOS 2.0中的新增功能)

URL The URL of the media file you want to play. The URL must specify a file; streamed media is not supported. The file may contain audio, video, or both.

URL您要播放的媒体文件的URL。 URL必须指定一个文件;不支持流媒体。该文件可能包含音频,视频或两者。

If you specify a URL for a file on a remote server, this method downloads the file first and displays a progress indicator showing the progress of the operation. Because WatchKit uses App Transport Security (ATS) when downloading files from a web server, the file must be on a secure server, and the URL must use the https scheme. If your server does not support ATS–level security, download the file yourself before playing it.

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

Use sharedcontainer, watch extensions, for storing the file.

使用sharedcontainer,watch extensions来存储文件。

Any audio you play using this method is routed to a paired Bluetooth audio device if one is available. If no Bluetooth audio device is available, audio is routed to to the Apple Watch speaker.

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