【发布时间】:2016-05-04 09:10:40
【问题描述】:
我似乎无法在互联网上找到任何关于它的信息..
我需要在特定事件上触发铃声(用户稍后可以选择),但现在只播放铃声(或音乐)就可以了。
【问题讨论】:
标签: c# mobile xamarin xamarin.ios ringtone
我似乎无法在互联网上找到任何关于它的信息..
我需要在特定事件上触发铃声(用户稍后可以选择),但现在只播放铃声(或音乐)就可以了。
【问题讨论】:
标签: c# mobile xamarin xamarin.ios ringtone
在 iOS 上没有用于播放铃声的 SDK API,但您可以播放本地文件。你看过 Xamarin 教程吗Playing Sound with AVAudioPlayer
这会让你像这样播放本地文件:
// Initialize background music
songURL = new NSUrl("Sounds/"+filename);
NSError err;
backgroundMusic = new AVAudioPlayer (songURL, "wav", out err);
backgroundMusic.Volume = MusicVolume;
backgroundMusic.FinishedPlaying += delegate {
backgroundMusic = null;
};
backgroundMusic.NumberOfLoops=-1;
backgroundMusic.Play();
backgroundSong=filename;
如果是消息声音(≤30秒),而不是铃声,您可以尝试使用AudioServicesPlaySystemSound
这里是所有system sound Ids 的列表,也在这个GitHub 上。 1007 是标准的 Tri-Tone 通知声音。
AudioServicesPlaySystemSound(1003);
有人谈论您的应用在使用AudioServicesPlaySystemSound 时被拒绝,但我看不到任何可靠的证据,这里也是Apple 播放system sound 的示例代码
iOS SDK 不捆绑这些声音文件,但它们位于设备上的/System/Library/Audio/UISounds/ 文件夹中。铃声位于此处/Library/Ringtones/ 有人确实提到这些是受版权保护的,所以如果您将它们捆绑在您的应用程序中,请注意。
然后像这样播放声音:
var s = new SystemSound (soundId);
s.PlayAlertSound ();
小心
捆绑来自 Apple 的受版权保护的声音可能会导致您的应用被拒绝
【讨论】: