如何为手表套件应用播放声音 [英] How to play a sound for watch kit app

查看:45
本文介绍了如何为手表套件应用播放声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,目前无法在手表上播放您的手表套件应用程序中的声音.如果是这种情况,播放声音的最佳方式是什么?目前我正在使用 openParentApplication:reply: 在播放声音的手机上运行代码.这是最好的方法吗?

From what I understand it is currently not possible to play a sound from your watch kit app on the watch. If this is the case what is the best way to play a sound? Currently I am using openParentApplication:reply: to run code on the phone that plays the sound. Is this the best way?

更新:我还发现我可以使用与父应用程序相同的方法直接从手表扩展程序播放音频.不知道这是否会在不在模拟器上时实际播放.

Update: I also found that I can play audio directly from the watch extension using the same methods as in the parent app. No Idea if this will actually play when not on the simulator.

推荐答案

目前没有任何方法可以在 Watch 上播放音频.你的假设是 100% 正确的.Apple 不想在运行时将音频剪辑从 Watch Extension 传输到 Watch.目前,唯一支持的传输缓存系统是 图像.现在,您必须在 iOS 设备上播放音频.您可以使用以下方法之一触发播放声音:

There currently isn't any way to play audio on the Watch. Your assumptions are 100% correct. Apple doesn't want to have to transfer the audio clips from the Watch Extension to the Watch at runtime. Currently, the only supported transfer caching system is for images. For now, you will have to play the audio on the iOS device. You can use one of the following approaches to trigger playing the sound:

  • openParentApplication:reply: - 如果当前未运行,则在后台打开应用
  • 通过诸如MMWormhole
  • 之类的方式发送达尔文通知
  • openParentApplication:reply: - opens app in the background if not currently running
  • Darwin notifications through something like MMWormhole

从 Watch 扩展播放声音肯定是一个灰色地带.我的猜测是它会在 iOS 设备上播放,或者在使用设备进行测试时根本不播放.不过,我当然会建议不要采用这种方法.您的 Watch Extension 通常只会在很短的时间内打开.播放来自 iOS 应用的音频会是一个更好的主意,因为它可以保证继续运行.

Playing the sound from the Watch extension is certainly a gray area. My guess is that it will play on the iOS Device or not play at all when testing with devices. I would certainly advise against that approach though. Your Watch Extension will typically only be open for a VERY short period of time. It would be a much better idea to play the audio from the iOS app since that is guaranteed to continue running.

这篇关于如何为手表套件应用播放声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆