且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从 Apple Watch 扬声器播放声音

更新时间:2023-12-03 17:45:22

从 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];