Play a Sound or Alert
From $1
Table of contents
To play a simple sound, do the following:
- Include your sound file in your project, and ensure that the Build Action is set to "Content", so that the audio is copied to your application on the device.
Add "using MonoTouch.AudioToolbox" to your program, and then use this code snippet:
//
// Setup your session
//
AudioSession.Initialize();
AudioSession.Category = AudioSessionCategory.MediaPlayback;
AudioSession.SetActive(true);
//
// Play the file
//
var sound = SystemSound.FromFile (new NSUrl ("File.caf"));
sound.PlaySystemSound ();
If you want to play an Alert instead (the meaning of an alert depends on the current user settings and the device, for more information see Apple's documentation) use the PlayAlertSound method instead.
- Tag page
- What links here
[MISSING: skin.common.header-gallery-count]
| Images 0 | ||
|---|---|---|
| No images to display in the gallery. |
Page last modified 06:06, 2 Mar 2010 by Miguel