如何在我的 Xamarin.iOS 应用程序中播放来自 iPhone 的铃声?
How to play a ringtone from the iPhone in my Xamarin.iOS application?
我似乎无法在互联网上找到任何关于它的信息..
我需要在特定事件上触发铃声(用户稍后可以选择),但现在只播放铃声(或音乐)就可以了。
没有 SDK API 可以在 iOS 上播放铃声,但您可以播放本地文件。您看过 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, also at this GitHub 的列表。 1007是标准的三音提示音。
AudioServicesPlaySystemSound(1003);
有一些关于您的应用在使用 AudioServicesPlaySystemSound
时被拒绝的说法,但我看不到任何确凿的证据,这里还有 Apple 播放 system sound
的示例代码
iOS SDK 不捆绑这些声音文件,但它们在设备上的 /System/Library/Audio/UISounds/
文件夹中。铃声位于此处 /Library/Ringtones/
有人提到这些受版权保护,因此如果您将它们捆绑在您的应用程序中,请当心。
然后像这样播放声音:
var s = new SystemSound (soundId);
s.PlayAlertSound ();
当心
捆绑来自 Apple 的受版权保护的声音可能会导致您的应用被拒绝
我似乎无法在互联网上找到任何关于它的信息..
我需要在特定事件上触发铃声(用户稍后可以选择),但现在只播放铃声(或音乐)就可以了。
没有 SDK API 可以在 iOS 上播放铃声,但您可以播放本地文件。您看过 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, also at this GitHub 的列表。 1007是标准的三音提示音。
AudioServicesPlaySystemSound(1003);
有一些关于您的应用在使用 AudioServicesPlaySystemSound
时被拒绝的说法,但我看不到任何确凿的证据,这里还有 Apple 播放 system sound
iOS SDK 不捆绑这些声音文件,但它们在设备上的 /System/Library/Audio/UISounds/
文件夹中。铃声位于此处 /Library/Ringtones/
有人提到这些受版权保护,因此如果您将它们捆绑在您的应用程序中,请当心。
然后像这样播放声音:
var s = new SystemSound (soundId);
s.PlayAlertSound ();
当心
捆绑来自 Apple 的受版权保护的声音可能会导致您的应用被拒绝