【问题标题】:How to play a tone using Xamarin on iOS如何在 iOS 上使用 Xamarin 播放音调
【发布时间】:2014-10-09 09:45:19
【问题描述】:

我希望我的基于 Xamarin 的 iPhone 应用播放自定义音调,但我是 iOS 开发新手,正在努力寻找一种简单的方法。

最终,我希望能够发出金属探测器类型的声音,其中不常见的哔哔声变得更加频繁并最终持续,但首先,一个简单的正弦波就足够了。

我找到了 objectal-monotouch 库 (https://github.com/tescott/objectal-monotouch) 和 Objective-C 中的示例项目 (http://www.cocoawithlove.com/2010/10/ios-tone-generator-introduction-to.html),但前者对 monotouch 的引用已经过时,而后者是相当多的代码为非 Objective-C 程序员转换。

在我开始使用这些路径之前,任何人都可以推荐任何示例代码或最新的库来更简单地实现这一点吗?

非常感谢,

理查德

编辑:我继续移植 cocoawithlove 示例。如果有兴趣请联系我。这不是火箭科学,但也不是微不足道的,因为 Xamarin API 存在显着差异。如果有人知道任何有助于此类转换的资源(例如,从本机 API 到 Xamarin 或更好的 Xamarin 文档的映射!)请告诉我!

【问题讨论】:

  • 有没有机会分享转换后的代码?我知道是一年后,但这是互联网 :)

标签: ios iphone audio xamarin.ios xamarin


【解决方案1】:
NSUrl soundURL = NSUrl.FromFilename(soundfile);

using (AVAudioPlayer player = AVAudioPlayer.FromUrl(soundURL)) {
    player.Volume = 1.0f;
    player.PrepareToPlay();
    player.Play();
}

【讨论】:

  • 请编辑您的答案以添加对您的代码如何工作以及它如何解决 OP 问题的解释。很多 SO 发帖人都是新手,看不懂你贴的代码。
  • 这真的很简单 - 不需要解释,如果你需要解释 - 回到 101 的开发阶段。
  • 以下是在 Xamarin.iOS 中播放声音的两个很好的参考:Xamarin - Playing Sound with AVAudioPlayer Apple's AVAudioPlayer Reference
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-03-23
  • 1970-01-01
  • 1970-01-01
  • 2018-12-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多