Ejemplo n.º 1
0
        void SetupRecorder()
        {
            // An extension is required otherwise the file does not save to a format that browsers support (mp4)
            // Note: output the file rather than the path as the path is calculated via PrivatePath interface in the PCL
            var documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

            filename = Path.Combine(documents, DateTimeOffset.Now.ToUnixTimeSeconds().ToString() + ".3gp");

            var audioSession = AVAudioSession.SharedInstance();
            var err          = audioSession.SetCategory(AVAudioSessionCategory.PlayAndRecord);

            err = audioSession.SetActive(true);

            NSObject[] values =
            {
                NSNumber.FromFloat(8000.0f),
                NSNumber.FromInt32((int)AudioToolbox.AudioFormatType.MPEG4AAC),
                NSNumber.FromInt32(1)
            };

            NSObject[] keys =
            {
                AVAudioSettings.AVSampleRateKey,
                AVAudioSettings.AVFormatIDKey,
                AVAudioSettings.AVNumberOfChannelsKey
            };

            recorder = AVAudioRecorder.Create(
                NSUrl.FromFilename(filename),
                new AudioSettings(NSDictionary.FromObjectsAndKeys(values, keys)),
                out var error
                );
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Trie to set up a recorder with CreateOutputUrl Url.
        /// </summary>
        private bool PrepareAudioRecording()
        {
            var result = false;

            recorder = AVAudioRecorder.Create(CreateOutputUrl(), audioSettings, out NSError error);
            if (error == null)
            {
                // Set Recorder to Prepare To Record
                if (!recorder.PrepareToRecord())
                {
                    recorder.Dispose();
                    recorder = null;
                }
                else
                {
                    recorder.FinishedRecording += OnFinishedRecording;
                    result = true;
                }
            }
            else
            {
                Console.WriteLine("creation error");
            }

            return(result);
        }
Ejemplo n.º 3
0
        protected override bool NativeStopRecording()
        {
            AudioRecorder?.Stop();
            AudioRecorder = null;

            return(true);
        }
Ejemplo n.º 4
0
        private void OnFinishedRecording(object sender, AVStatusEventArgs e)
        {
            recorder.Dispose();
            recorder = null;

            Console.WriteLine($"Done Recording (status: {e.Status})");
        }
Ejemplo n.º 5
0
 public string StopRecord()
 {
     recorder.Stop();
     recorder.Dispose();
     recorder = null;
     return(sFileName);
 }
Ejemplo n.º 6
0
        public void RecordStart(string fileName)
        {
            var filePath = _Storage.GetPath(fileName);

            System.Diagnostics.Debug.WriteLine(string.Format("*** AudioService.RecordStart - Preparing to record to: {0}.", filePath));

            _OutputUrl = NSUrl.FromFilename(filePath);

            //  apply recorder settings
            _Recorder = AVAudioRecorder.Create(_OutputUrl, new AudioSettings(_Settings), out _Error);

            //  record
            if (!_Recorder.PrepareToRecord())
            {
                _Recorder.Dispose();
                _Recorder = null;
                throw new Exception("Could not prepare recording");
            }

            _Recorder.FinishedRecording += delegate(object sender, AVStatusEventArgs e)
            {
                _Recorder.Dispose();
                _Recorder = null;
                Console.WriteLine("Done Recording (status: {0})", e.Status);
            };

            _Recorder.Record();

            System.Diagnostics.Debug.WriteLine("*** AudioService.RecordStart - Recording started");
        }
Ejemplo n.º 7
0
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);
            if (observer != null)
            {
                observer.Dispose();
                observer = null;
            }

            if (player != null)
            {
                player.Dispose();
                player = null;
            }

            if (recorder != null)
            {
                recorder.Dispose();
                recorder = null;
            }

            if (audioFilePath != null)
            {
                audioFilePath.Dispose();
                audioFilePath = null;
            }
        }
Ejemplo n.º 8
0
        bool PrepareAudioRecording()
        {
            audioFilePath = CreateOutputUrl();

            var audioSettings = new AudioSettings {
                SampleRate     = 44100,
                Format         = AudioToolbox.AudioFormatType.MPEG4AAC,
                NumberChannels = 1,
                AudioQuality   = AVAudioQuality.High
            };

            //Set recorder parameters
            NSError error;

            recorder = AVAudioRecorder.Create(audioFilePath, audioSettings, out error);
            if (error != null)
            {
                Console.WriteLine(error);
                return(false);
            }

            //Set Recorder to Prepare To Record
            if (!recorder.PrepareToRecord())
            {
                recorder.Dispose();
                recorder = null;
                return(false);
            }

            recorder.FinishedRecording += OnFinishedRecording;

            return(true);
        }
Ejemplo n.º 9
0
 public void StopRecording()
 {
     if (_recorder == null)
     {
         return;
     }
     _recorder.Stop();
     _recorder = null;
 }
Ejemplo n.º 10
0
        public static void Record(string url)
        {
            var parameters = HttpUtility.ParseQueryString(url.Substring(url.IndexOf('?')));

            if (parameters != null)
            {
                if (parameters.ContainsKey("callback"))
                {
                    callback = parameters ["callback"];
                }
                else
                {
                    throw new ArgumentException("Audio recording requires a callback URI.");
                }
            }

            NSObject[] values = new NSObject[]
            {
                NSNumber.FromInt32((int)AudioFormatType.MPEG4AAC),
                NSNumber.FromInt32(2),
                NSNumber.FromInt32((int)AVAudioQuality.Max)
            };

            NSObject[] keys = new NSObject[]
            {
                AVAudioSettings.AVFormatIDKey,
                AVAudioSettings.AVNumberOfChannelsKey,
                AVAudioSettings.AVEncoderAudioQualityKey
            };

            NSDictionary settings = NSDictionary.FromObjectsAndKeys(values, keys);

            string audioFilePath = Path.Combine(TouchFactory.Instance.TempPath, Guid.NewGuid().ToString() + ".aac");

            NSError error = null;

            audioRecorder = AVAudioRecorder.Create(NSUrl.FromFilename(audioFilePath), new AudioSettings(settings), out error);

            var actionSheet = new UIActionSheet(string.Empty)
            {
                TouchFactory.Instance.GetResourceString("RecordAudio"),
                TouchFactory.Instance.GetResourceString("Cancel"),
            };

            actionSheet.CancelButtonIndex = 1;
            actionSheet.Style             = UIActionSheetStyle.BlackTranslucent;
            actionSheet.ShowInView(TouchFactory.Instance.TopViewController.View);
            actionSheet.Clicked += delegate(object sender, UIButtonEventArgs args)
            {
                switch (args.ButtonIndex)
                {
                case 0:
                    StartRecording();
                    break;
                }
            };
        }
Ejemplo n.º 11
0
        public void PrepareRecorder()
        {
            if (Recorder != null)
            {
                Recorder.Dispose();
            }
            var audioSession = AVAudioSession.SharedInstance();
            var err          = audioSession.SetCategory(AVAudioSessionCategory.PlayAndRecord);

            if (err != null)
            {
                Console.WriteLine("audioSession: {0}", err);
            }
            err = audioSession.SetActive(true);
            if (err != null)
            {
                Console.WriteLine("audioSession: {0}", err);
            }

            Console.WriteLine("Audio File Path: " + AudioFilePath + AudioFileName);
            Url = NSUrl.FromFilename(AudioFilePath + AudioFileName + ".mp4");

            if (File.Exists(AudioFilePath + "/" + AudioFileName + ".mp4"))
            {
                File.Delete(AudioFilePath + "/" + AudioFileName + ".mp4");
            }

            //set up the NSObject Array of values that will be combined with the keys to make the NSDictionary
            NSObject[] values = new NSObject[] {
                NSNumber.FromFloat(44100.0f),
                //Sample Rate
                NSNumber.FromInt32((int)AudioToolbox.AudioFormatType.LinearPCM),
                //AVFormat
                NSNumber.FromInt32(2),
                //Channels
                NSNumber.FromInt32(16),
                //PCMBitDepth
                NSNumber.FromBoolean(false),
                //IsBigEndianKey
                NSNumber.FromBoolean(false)
                //IsFloatKey
            };
            //Set up the NSObject Array of keys that will be combined with the values to make the NSDictionary
            NSObject[] keys = new NSObject[] {
                AVAudioSettings.AVSampleRateKey,
                AVAudioSettings.AVFormatIDKey,
                AVAudioSettings.AVNumberOfChannelsKey,
                AVAudioSettings.AVLinearPCMBitDepthKey,
                AVAudioSettings.AVLinearPCMIsBigEndianKey,
                AVAudioSettings.AVLinearPCMIsFloatKey
            };

            Settings = NSDictionary.FromObjectsAndKeys(values, keys);
            Recorder = AVAudioRecorder.Create(Url, new AudioSettings(Settings), out Error);
            Recorder.PrepareToRecord();
        }
Ejemplo n.º 12
0
        private bool PrepareVariables()
        {
            var audioSession = AVAudioSession.SharedInstance();
            var err          = audioSession.SetCategory(AVAudioSessionCategory.PlayAndRecord);

            if (err != null)
            {
                Console.WriteLine($"audioSession: {err}");
                return(false);
            }
            err = audioSession.SetActive(true);
            if (err != null)
            {
                Console.WriteLine($"audioSession: {err}");
                return(false);
            }
            //Declare string for application temp path and tack on the file extension
            string fileName = $"Myfile{DateTime.Now.ToString("yyyyMMddHHmmss")}.wav";

            audioFilePath = Path.Combine(Path.GetTempPath(), fileName);

            Console.WriteLine("Audio File Path: " + audioFilePath);

            url = NSUrl.FromFilename(audioFilePath);
            //set up the NSObject Array of values that will be combined with the keys to make the NSDictionary
            NSObject[] values =
            {
                NSNumber.FromFloat(44100.0f),                                    //Sample Rate
                NSNumber.FromInt32((int)AudioToolbox.AudioFormatType.LinearPCM), //AVFormat
                NSNumber.FromInt32(2),                                           //Channels
                NSNumber.FromInt32(16),                                          //PCMBitDepth
                NSNumber.FromBoolean(false),                                     //IsBigEndianKey
                NSNumber.FromBoolean(false)                                      //IsFloatKey
            };

            //Set up the NSObject Array of keys that will be combined with the values to make the NSDictionary
            NSObject[] keys =
            {
                AVAudioSettings.AVSampleRateKey,
                AVAudioSettings.AVFormatIDKey,
                AVAudioSettings.AVNumberOfChannelsKey,
                AVAudioSettings.AVLinearPCMBitDepthKey,
                AVAudioSettings.AVLinearPCMIsBigEndianKey,
                AVAudioSettings.AVLinearPCMIsFloatKey
            };

            //Set Settings with the Values and Keys to create the NSDictionary
            settings = NSDictionary.FromObjectsAndKeys(values, keys);

            //Set recorder parameters
            recorder = AVAudioRecorder.Create(url, new AudioSettings(settings), out error);

            //Set Recorder to Prepare To Record
            recorder.PrepareToRecord();
            return(true);
        }
Ejemplo n.º 13
0
        static void CreateRecorder()
        {
            ConfigureAudio(AVAudioSessionCategory.PlayAndRecord);

            Recorder = AVAudioRecorder.Create(NSUrl.FromFilename(Recording.FullName), GetSettings(), out var err);
            if (err != null)
            {
                throw new Exception("Could not create a recorder because: " + err.Description);
            }
        }
Ejemplo n.º 14
0
        static Background()
        {
            var settings = new AudioSettings();

            settings.AudioQuality = AVAudioQuality.Min;

            NSError error;

            audioRecorder = AVAudioRecorder.Create(new NSUrl(Manager.AudioFile), settings, out error);
        }
Ejemplo n.º 15
0
        void InitAudioRecorder()
        {
            var url = NSUrl.FromFilename(GetTempFileName());

            var settings = NSDictionary.FromObjectsAndKeys(objects, keys);

            recorder = AVAudioRecorder.Create(url, new AudioSettings(settings), out NSError error);

            recorder.PrepareToRecord();
        }
Ejemplo n.º 16
0
        void InitializeRecorder()
        {
            var audioSession = AVAudioSession.SharedInstance();
            var err          = audioSession.SetCategory(AVAudioSessionCategory.PlayAndRecord);

            if (err != null)
            {
                Console.WriteLine("audioSession: {0}", err);
                return;
            }
            err = audioSession.SetActive(true);
            if (err != null)
            {
                Console.WriteLine("audioSession: {0}", err);
                return;
            }

            var    localStorage  = PCLStorage.FileSystem.Current.LocalStorage.Path;
            string audioFilePath = localStorage + "/SmartCoffee.wav";

            Console.WriteLine("Audio File Path: " + audioFilePath);

            url = NSUrl.FromFilename(audioFilePath);

            //set up the NSObject Array of values that will be combined with the keys to make the NSDictionary
            var values = new NSObject[]
            {
                NSNumber.FromFloat(44100.0f),                                    //Sample Rate
                NSNumber.FromInt32((int)AudioToolbox.AudioFormatType.LinearPCM), //AVFormat
                NSNumber.FromInt32(2),                                           //Channels
                NSNumber.FromInt32(16),                                          //PCMBitDepth
                NSNumber.FromBoolean(false),                                     //IsBigEndianKey
                NSNumber.FromBoolean(false)                                      //IsFloatKey
            };

            //Set up the NSObject Array of keys that will be combined with the values to make the NSDictionary
            var keys = new NSObject[]
            {
                AVAudioSettings.AVSampleRateKey,
                AVAudioSettings.AVFormatIDKey,
                AVAudioSettings.AVNumberOfChannelsKey,
                AVAudioSettings.AVLinearPCMBitDepthKey,
                AVAudioSettings.AVLinearPCMIsBigEndianKey,
                AVAudioSettings.AVLinearPCMIsFloatKey
            };

            //Set Settings with the Values and Keys to create the NSDictionary
            settings = NSDictionary.FromObjectsAndKeys(values, keys);

            //Set recorder parameters
            recorder = AVAudioRecorder.Create(url, new AudioSettings(settings), out error);
            //Set Recorder to Prepare To Record
            recorder.PrepareToRecord();
        }
Ejemplo n.º 17
0
        static Background()
        {
            var settings = new AudioSettings();

            settings.AudioQuality = AVAudioQuality.Min;

            NSError error;

            audioRecorder = AVAudioRecorder.Create(new NSUrl(Manager.AudioFile), settings, out error);
            audioPlayer   = AVAudioPlayer.FromUrl(new NSUrl(NSBundle.MainBundle.PathForResource("3", "wav")));
        }
Ejemplo n.º 18
0
        bool PrepareAudioRecording()
        {
            //Declare string for application temp path and tack on the file extension
            string fileName      = string.Format("Myfile{0}.aac", DateTime.Now.ToString("yyyyMMddHHmmss"));
            string tempRecording = NSBundle.MainBundle.BundlePath + "/../tmp/" + fileName;

            Console.WriteLine(tempRecording);
            this.audioFilePath = NSUrl.FromFilename(tempRecording);

            //set up the NSObject Array of values that will be combined with the keys to make the NSDictionary
            NSObject[] values = new NSObject[]
            {
                NSNumber.FromFloat(44100.0f),
                NSNumber.FromInt32((int)MonoTouch.AudioToolbox.AudioFormatType.MPEG4AAC),
                NSNumber.FromInt32(1),
                NSNumber.FromInt32((int)AVAudioQuality.High)
            };
            //Set up the NSObject Array of keys that will be combined with the values to make the NSDictionary
            NSObject[] keys = new NSObject[]
            {
                AVAudioSettings.AVSampleRateKey,
                AVAudioSettings.AVFormatIDKey,
                AVAudioSettings.AVNumberOfChannelsKey,
                AVAudioSettings.AVEncoderAudioQualityKey
            };
            //Set Settings with the Values and Keys to create the NSDictionary
            settings = NSDictionary.FromObjectsAndKeys(values, keys);

            //Set recorder parameters
            NSError error;

            recorder = AVAudioRecorder.ToUrl(this.audioFilePath, settings, out error);
            if ((recorder == null) || (error != null))
            {
                Console.WriteLine(error);
                return(false);
            }

            //Set Recorder to Prepare To Record
            if (!recorder.PrepareToRecord())
            {
                recorder.Dispose();
                recorder = null;
                return(false);
            }

            recorder.FinishedRecording += delegate(object sender, AVStatusEventArgs e) {
                recorder.Dispose();
                recorder = null;
                Console.WriteLine("Done Recording (status: {0})", e.Status);
            };

            return(true);
        }
Ejemplo n.º 19
0
        public void CreateWithError()
        {
            var     url = NSUrl.FromFilename("/dev/fake.wav");
            NSError error;
            var     audioSettings = new AudioSettings(NSDictionary.FromObjectsAndKeys(Values, Keys));

            using (var recorder = AVAudioRecorder.Create(url, audioSettings, out error)) {
                Assert.Null(recorder);
                Assert.NotNull(error);
            }
        }
Ejemplo n.º 20
0
        private void SetupRecorder(string sFileName)
        {
            var audioSession = AVAudioSession.SharedInstance();
            var err          = audioSession.SetCategory(AVAudioSessionCategory.PlayAndRecord);

            if (err != null)
            {
                //Console.WriteLine("audioSession: {0}", err);
                //return false;
            }

            err = audioSession.SetActive(true);
            if (err != null)
            {
                //Console.WriteLine("audioSession: {0}", err);
                //return false;
            }

            this.sFileName = sFileName;
            //Declare string for application temp path and tack on the file extension
            //string fileName = string.Format("{0}.wav", DateTime.Now.ToString("yyyyMMddHHmmss"));
            string audioFilePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), sFileName);

            url = NSUrl.FromFilename(audioFilePath);
            //set up the NSObject Array of values that will be combined with the keys to make the NSDictionary
            NSObject[] values = new NSObject[]
            {
                NSNumber.FromFloat(44100.0f),                                   //Sample Rate
                NSNumber.FromInt32((int)AudioToolbox.AudioFormatType.MPEG4AAC), //AVFormat
                NSNumber.FromInt32(2),                                          //Channels
                NSNumber.FromInt32(16),                                         //PCMBitDepth
                NSNumber.FromInt32((int)AVAudioQuality.High),
                NSNumber.FromBoolean(false),                                    //IsBigEndianKey
                NSNumber.FromBoolean(false)                                     //IsFloatKey
            };

            //Set up the NSObject Array of keys that will be combined with the values to make the NSDictionary
            NSObject[] keys = new NSObject[]
            {
                AVAudioSettings.AVSampleRateKey,
                AVAudioSettings.AVFormatIDKey,
                AVAudioSettings.AVNumberOfChannelsKey,
                AVAudioSettings.AVEncoderAudioQualityKey,
                AVAudioSettings.AVLinearPCMBitDepthKey,
                AVAudioSettings.AVLinearPCMIsBigEndianKey,
                AVAudioSettings.AVLinearPCMIsFloatKey,
            };

            //Set Settings with the Values and Keys to create the NSDictionary
            settings = NSDictionary.FromObjectsAndKeys(values, keys);

            //Set recorder parameters
            this.recorder = AVAudioRecorder.Create(url, new AudioSettings(settings), out error);
        }
Ejemplo n.º 21
0
        bool PrepareAudioRecording(bool isLeft)
        {
            //Declare string for application temp path and tack on the file extension
            string fileName      = string.Format("Myfile{0}.aac", DateTime.Now.ToString("yyyyMMddHHmmss"));
            string tempRecording = NSBundle.MainBundle.BundlePath + "/../tmp/" + fileName;

            Console.WriteLine(tempRecording);
            this.audioFilePath = NSUrl.FromFilename(tempRecording);

            if (isLeft)
            {
                audioLeft = this.audioFilePath.ToString();
//				detailViewController.NewSndPath (audioLeft, true);
            }
            else
            {
                audioRight = this.audioFilePath.ToString();
//				detailViewController.NewSndPath (audioRight, false);
            }

            var audioSettings = new AudioSettings()
            {
                SampleRate     = 44100.0f,
                Format         = MonoTouch.AudioToolbox.AudioFormatType.MPEG4AAC,
                NumberChannels = 1,
                AudioQuality   = AVAudioQuality.High
            };

            //Set recorder parameters
            NSError error;

            recorder = AVAudioRecorder.Create(this.audioFilePath, audioSettings, out error);
            if ((recorder == null) || (error != null))
            {
                Console.WriteLine(error);
                return(false);
            }

            //Set Recorder to Prepare To Record
            if (!recorder.PrepareToRecord())
            {
                recorder.Dispose();
                recorder = null;
                return(false);
            }

            recorder.FinishedRecording += delegate(object sender, AVStatusEventArgs e) {
                recorder.Dispose();
                recorder = null;
                Console.WriteLine("Done Recording (status: {0})", e.Status);
            };

            return(true);
        }
Ejemplo n.º 22
0
        void InitializeRecorder()
        {
            var audioSession = AVAudioSession.SharedInstance();
            var err          = audioSession.SetCategory(AVAudioSessionCategory.PlayAndRecord);

            if (err != null)
            {
                Console.WriteLine("audioSession: {0}", err);
                return;
            }
            err = audioSession.SetActive(true);
            if (err != null)
            {
                Console.WriteLine("audioSession: {0}", err);
                return;
            }

            var audioFilePath = PortablePath.Combine(_localStorage, $"{_recordId}.wav");

            Console.WriteLine("Audio File Path: " + audioFilePath);

            _currentRecordUrl = NSUrl.FromFilename(audioFilePath);

            //set up the NSObject Array of values that will be combined with the keys to make the NSDictionary
            var values = new NSObject[]
            {
                NSNumber.FromFloat(_deviceService.AudioSampleRate),              //Sample Rate
                NSNumber.FromInt32((int)AudioToolbox.AudioFormatType.LinearPCM), //AVFormat
                NSNumber.FromInt32(2),                                           //Channels
                NSNumber.FromInt32(16),                                          //PCMBitDepth
                NSNumber.FromBoolean(false),                                     //IsBigEndianKey
                NSNumber.FromBoolean(false)                                      //IsFloatKey
            };

            //Set up the NSObject Array of keys that will be combined with the values to make the NSDictionary
            var keys = new NSObject[]
            {
                AVAudioSettings.AVSampleRateKey,
                AVAudioSettings.AVFormatIDKey,
                AVAudioSettings.AVNumberOfChannelsKey,
                AVAudioSettings.AVLinearPCMBitDepthKey,
                AVAudioSettings.AVLinearPCMIsBigEndianKey,
                AVAudioSettings.AVLinearPCMIsFloatKey
            };

            //Set Settings with the Values and Keys to create the NSDictionary
            _settings = NSDictionary.FromObjectsAndKeys(values, keys);

            //Set recorder parameters
            _recorder = AVAudioRecorder.Create(_currentRecordUrl, new AudioSettings(_settings), out _error);
            //Set Recorder to Prepare To Record
            _recorder.PrepareToRecord();
        }
Ejemplo n.º 23
0
        public Task <AudioRecordResult> Record(AudioRecordOptions options = null)
        {
            _options = options ?? AudioRecordOptions.Empty;

            _tcs = new TaskCompletionSource <AudioRecordResult>();

            var audioSession = AVAudioSession.SharedInstance();

            var err = audioSession.SetCategory(AVAudioSessionCategory.PlayAndRecord);

            if (err != null)
            {
                return(Task.FromResult(new AudioRecordResult($"AVAudioSession.SetCategory returned error '{err}'")));
            }

            err = audioSession.SetActive(true);
            if (err != null)
            {
                return(Task.FromResult(new AudioRecordResult($"AVAudioSession.SetActive returned error '{err}'")));
            }

            _audioFilePath = Path.Combine(Path.GetTempPath(), $"audiorec_{DateTime.Now.Ticks}.wav");

            Console.WriteLine("Audio File Path: " + _audioFilePath);

            var url = NSUrl.FromFilename(_audioFilePath);

            var config = new Dictionary <NSObject, NSObject>
            {
                { AVAudioSettings.AVSampleRateKey, NSNumber.FromFloat((float)_options.SampleRate) },
                { AVAudioSettings.AVFormatIDKey, NSNumber.FromInt32((int)AudioToolbox.AudioFormatType.LinearPCM) },
                { AVAudioSettings.AVNumberOfChannelsKey, NSNumber.FromInt32(1) },
                { AVAudioSettings.AVLinearPCMBitDepthKey, NSNumber.FromInt32(16) },
                { AVAudioSettings.AVLinearPCMIsBigEndianKey, NSNumber.FromBoolean(false) },
                { AVAudioSettings.AVLinearPCMIsFloatKey, NSNumber.FromBoolean(false) }
            };

            var settings = NSDictionary.FromObjectsAndKeys(config.Keys.ToArray(), config.Values.ToArray());

            _recorder = AVAudioRecorder.Create(url, new AudioSettings(settings), out err);
            if (err != null)
            {
                return(Task.FromResult(new AudioRecordResult($"AVAudioRecorder.Create returned error '{err}'")));
            }

            _recorder.PrepareToRecord();
            _recorder.Record();

            Task.Run(() => Timeout());

            return(_tcs.Task);
        }
Ejemplo n.º 24
0
        public void Start(string fileName, out string fileFullName)
        {
            //  var documentsPath = Path.GetTempPath();
            //  string libraryPath = Path.Combine(documentsPath, "MindCorners"); // Library folder
            // var filePath = Path.Combine(libraryPath, fileName);

            //var filePath = System.IO.Path.Combine(documentsPath,fileName);


            InitAudio();

            //Declare string for application temp path and tack on the file extension
            //string fileName = string.Format("Myfile{0}.wav", DateTime.Now.ToString("yyyyMMddHHmmss"));
            string audioFilePath = Path.Combine(Path.GetTempPath(), fileName);

            path         = audioFilePath;
            fileFullName = audioFilePath;
            Console.WriteLine("Audio File Path: " + audioFilePath);

            url = NSUrl.FromFilename(audioFilePath);
            //set up the NSObject Array of values that will be combined with the keys to make the NSDictionary
            NSObject[] values = new NSObject[]
            {
                NSNumber.FromFloat(44100.0f),                                    //Sample Rate
                NSNumber.FromInt32((int)AudioToolbox.AudioFormatType.LinearPCM), //AVFormat
                NSNumber.FromInt32(2),                                           //Channels
                NSNumber.FromInt32(16),                                          //PCMBitDepth
                NSNumber.FromBoolean(false),                                     //IsBigEndianKey
                NSNumber.FromBoolean(false)                                      //IsFloatKey
            };

            //Set up the NSObject Array of keys that will be combined with the values to make the NSDictionary
            NSObject[] keys = new NSObject[]
            {
                AVAudioSettings.AVSampleRateKey,
                AVAudioSettings.AVFormatIDKey,
                AVAudioSettings.AVNumberOfChannelsKey,
                AVAudioSettings.AVLinearPCMBitDepthKey,
                AVAudioSettings.AVLinearPCMIsBigEndianKey,
                AVAudioSettings.AVLinearPCMIsFloatKey
            };

            //Set Settings with the Values and Keys to create the NSDictionary
            settings = NSDictionary.FromObjectsAndKeys(values, keys);

            //Set recorder parameters
            recorder = AVAudioRecorder.Create(url, new AudioSettings(settings), out error);
            //Set Recorder to Prepare To Record
            recorder.PrepareToRecord();

            recorder.Record();
        }
Ejemplo n.º 25
0
 public void Dispose()
 {
     if (_Disposed)
     {
         return;
     }
     if (_Recorder != null)
     {
         _Recorder.Dispose();
         _Recorder = null;
     }
     _Disposed = true;
 }
Ejemplo n.º 26
0
        public void Create()
        {
            TestRuntime.RequestMicrophonePermission();

            var     url = NSUrl.FromFilename("/dev/null");
            NSError error;
            var     audioSettings = new AudioSettings(NSDictionary.FromObjectsAndKeys(Values, Keys));

            using (var recorder = AVAudioRecorder.Create(url, audioSettings, out error)) {
                Assert.NotNull(recorder);
                Assert.Null(error);
            }
        }
Ejemplo n.º 27
0
        public void deleteRecord()
        {
            if (player != null)
            {
                player.Dispose();
                player = null;
            }

            if (recorder != null)
            {
                recorder.Dispose();
                recorder = null;
            }
        }
Ejemplo n.º 28
0
        void InitializeRecorder()
        {
            var audioSession = AVAudioSession.SharedInstance();
            var err          = audioSession.SetCategory(AVAudioSessionCategory.PlayAndRecord);

            if (err != null)
            {
                Console.WriteLine("audioSession: {0}", err);
                return;
            }

            err = audioSession.SetActive(true);
            if (error != null)
            {
                Console.WriteLine("audioSession: {0}", err);
                return;
            }

            var    localStorage  = PCLStorage.FileSystem.Current.LocalStorage.Path;
            string audioFilePath = localStorage + "/PatientNotes.wav";

            Console.WriteLine("Audio file path: " + audioFilePath);

            url = NSUrl.FromFilename(audioFilePath);

            var values = new NSObject[]
            {
                NSNumber.FromFloat(8000.0f),                                     // Sample Rate
                NSNumber.FromInt32((int)AudioToolbox.AudioFormatType.LinearPCM), // AVFormat
                NSNumber.FromInt32(1),                                           // Channels
                NSNumber.FromInt32(16),                                          // PCMBitDepth
                NSNumber.FromBoolean(false),                                     // IsBigEndianKey
                NSNumber.FromBoolean(false)                                      // IsFloatKey
            };

            var keys = new NSObject[]
            {
                AVAudioSettings.AVSampleRateKey,
                AVAudioSettings.AVFormatIDKey,
                AVAudioSettings.AVNumberOfChannelsKey,
                AVAudioSettings.AVLinearPCMBitDepthKey,
                AVAudioSettings.AVLinearPCMIsBigEndianKey,
                AVAudioSettings.AVLinearPCMIsFloatKey
            };

            settings = NSDictionary.FromObjectsAndKeys(values, keys);
            recorder = AVAudioRecorder.Create(url, new AudioSettings(settings), out error);
            recorder.PrepareToRecord();
        }
Ejemplo n.º 29
0
        public Task PlatformRecordAsync()
        {
            InitAudioSession();

            _audioFilePath = Path.Combine(Kit.CachePath, Kit.NewGuid + ".m4a");
            var url = NSUrl.FromFilename(_audioFilePath);

            _recorder = AVAudioRecorder.Create(url, new AudioSettings(_settings), out var error);
            if (error != null)
            {
                ThrowNSError(error);
            }
            _recorder.Record();
            return(Task.CompletedTask);
        }
Ejemplo n.º 30
0
		private void getSettings()
		{

			var documents = Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments);
			var library = System.IO.Path.Combine (documents, "..", "Library");
			var urlpath = System.IO.Path.Combine (library, "audioRecording.wav");

			session = AVAudioSession.SharedInstance ();
			session.SetCategory (AVAudioSessionCategory.PlayAndRecord);

			url = new NSUrl (urlpath, false);


			NSFileManager manager = new NSFileManager ();
			NSError error = new NSError (new NSString ("world"), 1);

			//if there is a file at the save location, delete it so we can save there
			if (manager.FileExists (urlpath)) {
				Console.WriteLine ("Deleting File");
				manager.Remove (urlpath, out error);
				Console.WriteLine ("Deleted File");
			}

			NSObject[] values = new NSObject[]
			{
				NSNumber.FromFloat (44100.0f), //Sample Rate
				NSNumber.FromInt32 ((int)MonoTouch.AudioToolbox.AudioFormatType.LinearPCM), //AVFormat
				NSNumber.FromInt32 (2), //Channels
				NSNumber.FromInt32 (16), //PCMBitDepth
				NSNumber.FromBoolean (false), //IsBigEndianKey
				NSNumber.FromBoolean (false) //IsFloatKey
			};

			NSObject[] keys = new NSObject[] {
				AVAudioSettings.AVSampleRateKey,
				AVAudioSettings.AVFormatIDKey,
				AVAudioSettings.AVNumberOfChannelsKey,
				AVAudioSettings.AVLinearPCMBitDepthKey,
				AVAudioSettings.AVLinearPCMIsBigEndianKey,
				AVAudioSettings.AVLinearPCMIsFloatKey
			};

			settings = NSDictionary.FromObjectsAndKeys (values, keys);

			recorder = AVAudioRecorder.ToUrl (url, settings, out error);


		}
Ejemplo n.º 31
0
        public Task <FileData> PlatformStopAsync()
        {
            if (_recorder == null)
            {
                return(Task.FromResult(default(FileData)));
            }

            _recorder.Stop();
            _recorder.Dispose();
            _recorder = null;
            AVAudioSession.SharedInstance().SetActive(false);

            FileInfo fi = new FileInfo(_audioFilePath);

            return(Task.FromResult(new FileData(_audioFilePath, fi.Name, (ulong)fi.Length)));
        }
        /// <summary>
        /// Views the did load.
        /// </summary>
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();

            //
             m_navigationTitle = @"Audio Recorder";

            //
            this.View.TintColor = NormalTintColor;
            mMusicFlowView.BackgroundColor = this.View.BackgroundColor;
            mMusicFlowView.IdleAmplitude = 0;

            //Unique recording URL
            var fileName = NSProcessInfo.ProcessInfo.GloballyUniqueString;

            var documents = Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments);
            var tmp = Path.Combine (documents, "..", "tmp");

            m_recordingFilePath = Path.Combine(tmp,String.Format("{0}.m4a",fileName));
             {

                m_flexItem1 = new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace,null,null);
                m_flexItem2 = new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace,null,null);

                var img = UIImage.FromBundle("audio_record");

                m_recordButton = new UIBarButtonItem(img,UIBarButtonItemStyle.Plain,RecordingButtonAction);
                m_playButton = new UIBarButtonItem(UIBarButtonSystemItem.Play,PlayAction);
                m_pauseButton = new UIBarButtonItem(UIBarButtonSystemItem.Pause,PauseAction);
                m_trashButton = new UIBarButtonItem(UIBarButtonSystemItem.Trash,DeleteAction);

                this.SetToolbarItems (new UIBarButtonItem[]{ m_playButton, m_flexItem1, m_recordButton, m_flexItem2, m_trashButton}, false);

                 m_playButton.Enabled = false;
                 m_trashButton.Enabled = false;
             }

             // Define the recorder setting
             {
                var audioSettings = new AudioSettings () {
                    Format = AudioFormatType.MPEG4AAC,
                    SampleRate = 44100.0f,
                    NumberChannels = 2,
                };

                NSError err = null;

                m_audioRecorder = AVAudioRecorder.Create (NSUrl.FromFilename (m_recordingFilePath), audioSettings,out err);

                // Initiate and prepare the recorder
                m_audioRecorder.WeakDelegate = this;
                m_audioRecorder.MeteringEnabled = true;

                mMusicFlowView.PrimaryWaveLineWidth = 3.0f;
                mMusicFlowView.SecondaryWaveLineWidth = 1.0f;
             }

             //Navigation Bar Settings
             {
                this.NavigationItem.Title = @"Audio Recorder";
                m_cancelButton = new UIBarButtonItem(UIBarButtonSystemItem.Cancel,CancelAction);
                this.NavigationItem.LeftBarButtonItem = m_cancelButton;

                m_doneButton = new UIBarButtonItem(UIBarButtonSystemItem.Done, DoneAction);
             }

             //Player Duration View
            {
                m_viewPlayerDuration = new UIView ();
                m_viewPlayerDuration.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
                m_viewPlayerDuration.BackgroundColor = UIColor.Clear;

                m_labelCurrentTime = new UILabel ();
                m_labelCurrentTime.Text = NSStringExtensions.TimeStringForTimeInterval (0);
                m_labelCurrentTime.Font =  UIFont.BoldSystemFontOfSize(14.0f);
                m_labelCurrentTime.TextColor = NormalTintColor;
                m_labelCurrentTime.TranslatesAutoresizingMaskIntoConstraints = false;

                m_playerSlider = new UISlider(new CGRect(0, 0, this.View.Bounds.Size.Width, 64));
                 m_playerSlider.MinimumTrackTintColor = PlayingTintColor;
                 m_playerSlider.Value = 0;

                m_playerSlider.TouchDown += SliderStart;
                m_playerSlider.ValueChanged += SliderMoved;
                m_playerSlider.TouchUpInside += SliderEnd;
                m_playerSlider.TouchUpOutside += SliderEnd;
                 m_playerSlider.TranslatesAutoresizingMaskIntoConstraints = false;

                m_labelRemainingTime = new UILabel();
                m_labelCurrentTime.Text = NSStringExtensions.TimeStringForTimeInterval (0);
                 m_labelRemainingTime.UserInteractionEnabled = true;
                m_labelRemainingTime.AddGestureRecognizer (new UITapGestureRecognizer(TapRecognizer));
                m_labelRemainingTime.Font = m_labelCurrentTime.Font;
                 m_labelRemainingTime.TextColor = m_labelCurrentTime.TextColor;
                 m_labelRemainingTime.TranslatesAutoresizingMaskIntoConstraints = false;

                m_viewPlayerDuration.Add (m_labelCurrentTime);
                m_viewPlayerDuration.Add (m_playerSlider);
                m_viewPlayerDuration.Add (m_labelRemainingTime);

                NSLayoutConstraint constraintCurrentTimeLeading = NSLayoutConstraint.Create (m_labelCurrentTime,NSLayoutAttribute.Leading,NSLayoutRelation.Equal,m_viewPlayerDuration,NSLayoutAttribute.Leading,1.0f, 10.0f);
                NSLayoutConstraint constraintCurrentTimeTrailing =  NSLayoutConstraint.Create (m_playerSlider,NSLayoutAttribute.Leading,NSLayoutRelation.Equal,m_labelCurrentTime,NSLayoutAttribute.Trailing,1.0f,10);

                NSLayoutConstraint constraintRemainingTimeLeading =  NSLayoutConstraint.Create (m_labelRemainingTime,NSLayoutAttribute.Leading,NSLayoutRelation.Equal,m_playerSlider,NSLayoutAttribute.Trailing,1.0f, 10.0f);
                NSLayoutConstraint constraintRemainingTimeTrailing =  NSLayoutConstraint.Create (m_viewPlayerDuration,NSLayoutAttribute.Trailing,NSLayoutRelation.Equal,m_labelRemainingTime,NSLayoutAttribute.Trailing,1.0f,10.0f);

                NSLayoutConstraint constraintCurrentTimeCenter = NSLayoutConstraint.Create (m_labelCurrentTime,NSLayoutAttribute.CenterY,NSLayoutRelation.Equal,m_viewPlayerDuration,NSLayoutAttribute.CenterY,1.0f,0.0f);

                NSLayoutConstraint constraintSliderCenter = NSLayoutConstraint.Create (m_playerSlider,NSLayoutAttribute.CenterY,NSLayoutRelation.Equal,m_viewPlayerDuration,NSLayoutAttribute.CenterY,1.0f,0.0f);

                NSLayoutConstraint constraintRemainingTimeCenter = NSLayoutConstraint.Create (m_labelRemainingTime,NSLayoutAttribute.CenterY,NSLayoutRelation.Equal,m_viewPlayerDuration,NSLayoutAttribute.CenterY,1.0f,0.0f);

                m_viewPlayerDuration.AddConstraints(new NSLayoutConstraint[]{constraintCurrentTimeLeading,constraintCurrentTimeTrailing,constraintRemainingTimeLeading,constraintRemainingTimeTrailing,constraintCurrentTimeCenter,constraintSliderCenter,constraintRemainingTimeCenter});

            }
        }
 public void AudioRecorderDidFinishRecording(AVAudioRecorder recorder, Boolean flag)
 {
 }
 public void AudioRecorderEncodeErrorDidOccur(AVAudioRecorder recorder, NSError error)
 {
 }
        bool PrepareAudioRecording()
        {
            //Declare string for application temp path and tack on the file extension
            string fileName = string.Format("Myfile{0}.aac", DateTime.Now.ToString("yyyyMMddHHmmss"));
            string tempRecording = NSBundle.MainBundle.BundlePath + "/../tmp/" + fileName;

            Console.WriteLine(tempRecording);
            this.audioFilePath = NSUrl.FromFilename(tempRecording);

            var audioSettings = new AudioSettings()
            {
                SampleRate = 44100.0f,
                Format = MonoTouch.AudioToolbox.AudioFormatType.MPEG4AAC,
                NumberChannels = 1,
                AudioQuality = AVAudioQuality.High
            };

            //Set recorder parameters
            NSError error;
            recorder = AVAudioRecorder.Create(this.audioFilePath, audioSettings, out error);
            if ((recorder == null) || (error != null))
            {
                Console.WriteLine(error);
                return false;
            }

            //Set Recorder to Prepare To Record
            if (!recorder.PrepareToRecord())
            {
                recorder.Dispose();
                recorder = null;
                return false;
            }

            recorder.FinishedRecording += delegate (object sender, AVStatusEventArgs e)
            {
                recorder.Dispose();
                recorder = null;
                Console.WriteLine("Done Recording (status: {0})", e.Status);
            };

            return true;
        }
		bool PrepareAudioRecording ()
		{
			audioFilePath = CreateOutputUrl ();

			var audioSettings = new AudioSettings {
				SampleRate = 44100,
				Format = AudioToolbox.AudioFormatType.MPEG4AAC,
				NumberChannels = 1,
				AudioQuality = AVAudioQuality.High
			};

			//Set recorder parameters
			NSError error;
			recorder = AVAudioRecorder.Create (audioFilePath, audioSettings, out error);
			if (error != null) {
				Console.WriteLine (error);
				return false;
			}

			//Set Recorder to Prepare To Record
			if (!recorder.PrepareToRecord ()) {
				recorder.Dispose ();
				recorder = null;
				return false;
			}

			recorder.FinishedRecording += OnFinishedRecording;

			return true;
		}
Ejemplo n.º 37
0
        public static void StartRecording(string FileName)
        {
            NSObject[] values = new NSObject[]
            {
                NSNumber.FromFloat(44100.0f),
                NSNumber.FromInt32((int)AudioFormatType.LinearPCM),
                NSNumber.FromInt32(1),
                NSNumber.FromInt32((int)AVAudioQuality.High)
            };

            NSObject[] keys = new NSObject[]
            {
                AVAudioSettings.AVSampleRateKey,
                AVAudioSettings.AVFormatIDKey,
                AVAudioSettings.AVNumberOfChannelsKey,
                AVAudioSettings.AVEncoderAudioQualityKey
            };

            NSDictionary settings = NSDictionary.FromObjectsAndKeys (values, keys);
            NSUrl url = NSUrl.FromFilename(FileName);

            // Set recorder parameters
            NSError error;
            _recorder = AVAudioRecorder.ToUrl (url, settings, out error);
            if (_recorder == null){
                Console.WriteLine (error);
                return;
            }

            // Set Metering Enabled so you can get the time of the wav file
            _recorder.MeteringEnabled = true;
            _recorder.PrepareToRecord();
            _recorder.Record();
        }
Ejemplo n.º 38
0
        public void StartRecording()
        {
            NSError error;
            var audioSession = AVAudioSession.SharedInstance();
            var err = audioSession.SetCategory(AVAudioSessionCategory.PlayAndRecord);
            if (err != null)
            {
                Console.WriteLine("audioSession: {0}", err);
                return;
            }
            err = audioSession.SetActive(true);
            if (err != null)
            {
                Console.WriteLine("audioSession: {0}", err);
                return;
            }

            var documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            var temp = Path.Combine(documents, "..", "tmp");
            _recordedFileName = Path.Combine(temp, Guid.NewGuid() + ".mp4");

            using (var url = new NSUrl(_recordedFileName))
            {

                //set up the NSObject Array of values that will be combined with the keys to make the NSDictionary
                var values = new NSObject[]
                {
                    NSNumber.FromFloat(44100.0f), //Sample Rate
                    NSNumber.FromInt32((int) AudioToolbox.AudioFormatType.MPEG4AAC), //AVFormat
                    NSNumber.FromInt32(2), //Channels
                    NSNumber.FromInt32(16), //PCMBitDepth
                    NSNumber.FromBoolean(false), //IsBigEndianKey
                    NSNumber.FromBoolean(false) //IsFloatKey
                };

                //Set up the NSObject Array of keys that will be combined with the values to make the NSDictionary
                var keys = new NSObject[]
                {
                    AVAudioSettings.AVSampleRateKey,
                    AVAudioSettings.AVFormatIDKey,
                    AVAudioSettings.AVNumberOfChannelsKey,
                    AVAudioSettings.AVLinearPCMBitDepthKey,
                    AVAudioSettings.AVLinearPCMIsBigEndianKey,
                    AVAudioSettings.AVLinearPCMIsFloatKey
                };

                //Set Settings with the Values and Keys to create the NSDictionary
                var settings = NSDictionary.FromObjectsAndKeys(values, keys);

                //Set recorder parameters
                _recorder = AVAudioRecorder.Create(url, new AudioSettings(settings), out error);
            }

            //Set Recorder to Prepare To Record
            _recorder.PrepareToRecord();

            _recorder.Record();
        }
Ejemplo n.º 39
0
        bool PrepareAudioRecording()
        {
            // You must initialize an audio session before trying to record
            var audioSession = AVAudioSession.SharedInstance ();
            var err = audioSession.SetCategory (AVAudioSessionCategory.PlayAndRecord);
            if(err != null) {
                Console.WriteLine ("audioSession: {0}", err);
                return false;
            }
            err = audioSession.SetActive (true);
            if(err != null ){
                Console.WriteLine ("audioSession: {0}", err);
                return false;
            }

            // Declare string for application temp path and tack on the file extension
            string fileName = string.Format ("Myfile{0}.aac", DateTime.Now.ToString ("yyyyMMddHHmmss"));
            string tempRecording = Path.Combine (Path.GetTempPath (), fileName);

            Console.WriteLine (tempRecording);
            this.audioFilePath = NSUrl.FromFilename(tempRecording);

            //set up the NSObject Array of values that will be combined with the keys to make the NSDictionary
            NSObject[] values = new NSObject[]
            {
                NSNumber.FromFloat(44100.0f),
                NSNumber.FromInt32((int)AudioToolbox.AudioFormatType.MPEG4AAC),
                NSNumber.FromInt32(1),
                NSNumber.FromInt32((int)AVAudioQuality.High)
            };
            //Set up the NSObject Array of keys that will be combined with the values to make the NSDictionary
            NSObject[] keys = new NSObject[]
            {
                AVAudioSettings.AVSampleRateKey,
                AVAudioSettings.AVFormatIDKey,
                AVAudioSettings.AVNumberOfChannelsKey,
                AVAudioSettings.AVEncoderAudioQualityKey
            };
            //Set Settings with the Values and Keys to create the NSDictionary
            settings = NSDictionary.FromObjectsAndKeys (values, keys);

            //Set recorder parameters
            NSError error;
            recorder = AVAudioRecorder.Create(this.audioFilePath, new AudioSettings(settings), out error);
            if ((recorder == null) || (error != null)) {
                Console.WriteLine (error);
                return false;
            }

            //Set Recorder to Prepare To Record
            if (!recorder.PrepareToRecord ()) {
                recorder.Dispose ();
                recorder = null;
                return false;
            }

            recorder.FinishedRecording += delegate (object sender, AVStatusEventArgs e) {
                recorder.Dispose ();
                recorder = null;
                Console.WriteLine ("Done Recording (status: {0})", e.Status);
            };

            return true;
        }
		bool PrepareAudioRecording ()
		{
			//Declare string for application temp path and tack on the file extension
			string fileName = string.Format ("Myfile{0}.aac", DateTime.Now.ToString ("yyyyMMddHHmmss"));
			string tempRecording = NSBundle.MainBundle.BundlePath + "/../tmp/" + fileName;
			           
			Console.WriteLine (tempRecording);
			this.audioFilePath = NSUrl.FromFilename(tempRecording);
			
 			//set up the NSObject Array of values that will be combined with the keys to make the NSDictionary
			NSObject[] values = new NSObject[]
            {    
                NSNumber.FromFloat(44100.0f),
                NSNumber.FromInt32((int)MonoTouch.AudioToolbox.AudioFormatType.MPEG4AAC),
                NSNumber.FromInt32(1),
                NSNumber.FromInt32((int)AVAudioQuality.High)
            };
			//Set up the NSObject Array of keys that will be combined with the values to make the NSDictionary
            NSObject[] keys = new NSObject[]
            {
                AVAudioSettings.AVSampleRateKey,
                AVAudioSettings.AVFormatIDKey,
                AVAudioSettings.AVNumberOfChannelsKey,
                AVAudioSettings.AVEncoderAudioQualityKey
            };			
			//Set Settings with the Values and Keys to create the NSDictionary
			settings = NSDictionary.FromObjectsAndKeys (values, keys);
			
			//Set recorder parameters
			NSError error;
			recorder = AVAudioRecorder.ToUrl(this.audioFilePath, settings, out error);
			if ((recorder == null) || (error != null)) {
				Console.WriteLine (error);
				return false;
			}
			
			//Set Recorder to Prepare To Record
			if (!recorder.PrepareToRecord ()) {
				recorder.Dispose ();
				recorder = null;
				return false;
			}
			
			recorder.FinishedRecording += delegate (object sender, AVStatusEventArgs e) {
				recorder.Dispose ();
				recorder = null;
				Console.WriteLine ("Done Recording (status: {0})", e.Status);
			};
			
			return true;
		}
		void OnFinishedRecording (object sender, AVStatusEventArgs e)
		{
			recorder.Dispose ();
			recorder = null;
			Console.WriteLine ("Done Recording (status: {0})", e.Status);
		}
        /// <summary>
        /// Views the will disappear.
        /// </summary>
        /// <param name="animated">If set to <c>true</c> animated.</param>
        public override void ViewWillDisappear(Boolean animated)
        {
            base.ViewDidDisappear (animated);

            //
            if (m_audioPlayer != null)
            {
                m_audioPlayer.Delegate = null;
                m_audioPlayer.Stop ();
                m_audioPlayer = null;
            }

            if (m_audioRecorder != null) {
                m_audioRecorder.Delegate = null;
                m_audioRecorder.Stop ();
                m_audioRecorder = null;
            }
            StopUpdatingMeter ();
        }