In this recipe, we will learn how to use the device's microphone to record sounds.
Perform the following steps:
Add two buttons and a label to the view of the controller.
Enter the following
using
directives in theRecordSoundAppViewController.cs
file:using System.IO; using MonoTouch.AVFoundation; using MonoTouch.AudioToolbox;
Override the
ViewDidLoad
method and add the following code to it:NSUrl soundFileUrl = null; NSError error = null; AVAudioSession session = AVAudioSession.SharedInstance(); session.SetCategory(AVAudioSession.CategoryPlayAndRecord, out error); session.SetActive(true, out error); bool grantedPermission = false; session.RequestRecordPermission((granted) => { if (granted) { grantedPermission = true; string soundFile = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal...