本文介绍了从 Apple Watch 扬声器播放声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法从 Apple Watch 的扬声器中播放声音?我一直无法在网上找到任何文档.

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

推荐答案

从 watchOS 2 开始,现在可以使用 WKAudioFilePlayerWKInterfaceMovie.

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

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 扬声器播放声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 17:05