I want to play the keyboard 'click' sound when pressing buttons in my app. How do I access this sound clip with Monotouch? I don't want to pass my own sound using AudioToolbox SystemSound.FromFile(). So far all my searches have led to this solution or Objective-C code using 'AudioServicesCreateSystemSoundID' which I'm having trouble translating to C#.
-
http://stackoverflow.com/questions/7831671/playing-system-sound-without-importing-your-own – Erik Kerber Nov 25 '13 at 14:21
-
I'm looking for a C# example to work with – binncheol Nov 25 '13 at 15:36
-
The API's are 1:1. The only difference will be syntactical, I promise. – Erik Kerber Nov 25 '13 at 16:47
2 Answers
Well, that's not a 1:1 port from the code in Playing system sound without importing your own, but this should do the work:
var path = NSBundle.FromIdentifier ("com.Apple.UIKit").PathForResource ("Tock", "aiff");
using (var systemSound = new SystemSound (NSUrl.FromFilename (path))) {
systemSound.PlaySystemSound ();
}
SystemSound
is defined in MonoTouch.AudioToolbox
. Make sure to also look at MonoTouch Play System Sound and MonoTouch: Playing sound

- 1
- 1

- 16,134
- 5
- 57
- 85
-
Worked perfect for me, but had to use `"com.apple.UIKit"` instead of `"com.Apple.UIKit"` – user1829325 Jan 11 '14 at 09:13
With iOS 7.0 and higher, Stephane Delcroix answer seems not to work anymore...
But you can easily find the path to all the sounds in this nice project: https://github.com/TUNER88/iOSSystemSoundsLibrary
Here is the code I used und iOS 7 (take care, it might not work with the simulator!)
private const string NotificationSoundPath = @"/System/Library/Audio/UISounds/New/Fanfare.caf";
public static void TriggerSoundAndViber()
{
SystemSound notificationSound = SystemSound.FromFile(NotificationSoundPath);
notificationSound.AddSystemSoundCompletion(SystemSound.Vibrate.PlaySystemSound);
notificationSound.PlaySystemSound();
}
Also the using() construct in the answer above caused trouble in my case... it seems like it released the sound too early, I only can hear it (and even then not complete with viber) with a breakpoint on PlaySystemSound().

- 2,310
- 1
- 24
- 24