Simple sounds and alerts can be generated by System Sound Services using the SystemSound class in the Monotouch.AudioToolBox namespace. This recipe demonstrates how to use this class to make a sound, an alert (includes a sound and a vibration), and a vibration.
<li><p> First, add your desired sound file to the project directory, making sure to set the Build Action to Compile.</p>
</li>
<li><p> Next, declare a <code>NSUrl</code> variable and a <code>SystemSound</code> variable in our <code>SysSound_iOSViewController</code> class.</p>
<code> NSUrl url;
SystemSound newSound;</code>
<li><p> Once the variables are declared, assign a <code>NSUrl</code> to the <code>url</code> variable to reference your sound file in your <code>ViewDidLoad()</code> method:</p>
<pre><code>url = NSUrl.FromFilename ("Sounds/tap.aif");</code></pre>
</li>
<li><p> Next, assign a <code>SystemSound</code> instance to <code>newSound</code> using our <code>url</code> variable:</p>
<pre><code>newSound = new SystemSound (url);</code></pre>
</li>
<li><p> To play the sound, which in this case occurs when the <code>playSystemButton</code> is pressed, call <code>PlaySystemSound()</code> on our <code>SystemSound</code> instance.</p>
<pre><code>newSound.PlaySystemSound(); </code></pre>
</li>
<li><p> To play an alert, which plays the sound as well as vibrates the device, call <code>PlayAlertSound()</code> on our <code>SystemSound</code> instance.</p>
<pre><code>newSound.PlaySystemSound(); </code></pre>
</li>
<li><p>To simply vibrate the device, call the <code>PlaySystemSound()</code> method on the <code>Vibrate</code> field of the <code>SystemSound</code> class. </p>
<pre><code>SystemSound.Vibrate.PlaySystemSound ();</code></pre>
</li>
<li><p>Finally, the ensure the <code>NSUrl</code> you created is properly handled in memory, dispose of it in the <code>ViewWillDisappear(bool animated)</code> </p>
<pre><code> if (url != null)
url.Dispose ();
System Sound Services is meant to be used for UI sound effects and user alerts, rather than for sound effects in games. For devices that do not have a vibration element, the vibration constant does nothing. Additionally, the simulator does not handle vibration.
