public bool RecordAudio()
        {
            if (string.IsNullOrEmpty(folder) || string.IsNullOrEmpty(directoryname))
            {
                return false;
            }

            //--test
            
            // get all under root:
                /*
                var directories = Directory.EnumerateDirectories("./");
                foreach (var directory in directories)
                {
                    Console.WriteLine(directory);
                }
             */

            // read text file:
                /*
                var text = File.ReadAllText("TestData/ReadMe.txt");
                Console.WriteLine(text);
                */

            // xml stream reader:
               /*
                using (TextReader reader = new StreamReader("./TestData/test.xml"))
                {
                    System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(MyObject));
                    var xml = (MyObject)serializer.Deserialize(reader);
                }
                */

            try
            {
                Directory.CreateDirectory(directoryname);
                fileName = string.Format("Audio{0}.aac", DateTime.Now.ToString("yyyyMMddHHmmss"));
                path = Path.Combine(directoryname, fileName);

                _recorder = new MediaRecorder();
                _recorder.Reset();
				_recorder.SetAudioSource(AudioSource.Mic);
				_recorder.SetOutputFormat(OutputFormat.Default);
				_recorder.SetAudioEncoder(AudioEncoder.Aac);
                _recorder.SetOutputFile(path);
                _recorder.Prepare();
                _recorder.Start();
          
                return true;
            }
            catch (System.Exception ex)
            {
                _recorder = null;
                fileName = string.Empty;
                var test = ex.Message;
                return false;
            }
        }
 public void SetUpRecoder()
 {
     try
     {
         if (null == activity)
         {
             return;
         }
         if (userResponse == UserResponse.Video)
         {
             mediaRecorder = new MediaRecorder();
             mediaRecorder.Reset();
             mediaRecorder.SetAudioSource(AudioSource.Mic);
             mediaRecorder.SetVideoSource(VideoSource.Surface);
             mediaRecorder.SetOutputFormat(OutputFormat.Mpeg4);
             mediaRecorder.SetOutputFile(path + "/test.mp4");
             mediaRecorder.SetVideoEncodingBitRate(10000000);
             mediaRecorder.SetVideoFrameRate(30);
             mediaRecorder.SetVideoSize(videoSize.Width, videoSize.Height);
             mediaRecorder.SetVideoEncoder(VideoEncoder.H264);
             mediaRecorder.SetAudioEncoder(AudioEncoder.Aac);
             //int rotation = (int)activity.WindowManager.DefaultDisplay.Rotation;
             //int orientation = ORIENTATIONS.Get(rotation);
             if (LensFacing == CameraFacing.BACK)
             {
                 mediaRecorder.SetOrientationHint(90);
             }
             else
             {
                 mediaRecorder.SetOrientationHint(270);
             }
             mediaRecorder.SetMaxDuration(30000);
             mediaRecorder.Prepare();
         }
         else
         {
             mediaRecorder = new MediaRecorder();
             mediaRecorder.Reset();
             mediaRecorder.SetAudioSource(AudioSource.Mic);
             mediaRecorder.SetOutputFormat(OutputFormat.ThreeGpp);
             mediaRecorder.SetAudioEncoder(AudioEncoder.AmrNb);
             mediaRecorder.SetOutputFile(path + "/test.mp3");
             mediaRecorder.SetMaxDuration(30000);
             mediaRecorder.Prepare();
         }
     }
     catch (System.Exception ex)
     {
     }
 }
        public void OnCompletion(MediaRecorder recorder)
        {
            f.Close();

            if (!failed)
            {
                recorder.Reset();
                recorder.Release();
                try
                {
                    System.IO.File.Move(tempFilename, outputFilename);
                    System.IO.File.Delete(tempFilename);
                } catch
                {
                }
            }
        }
        //Used for entering the Mandarin_ma speech processing screen
        void HandleMandarin_Ma_Male_Select()
        {
            SetContentView (Resource.Layout.Mandarin_Mother_Male);

            string RecordPath = "/sdcard/Recording.mp3";
            //string RecordPath = Environment.getExternalStorageDirectory ()
            //	.getAbsolutePath () + "/Recording.mp3";

            //string RecordPath = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath + "/Recording.3gpp";
            //string RecordPath = this.file.getAbsolutePath().substring(8)

            Button PlayStock = FindViewById<Button> (Resource.Id.PlayMa);
            PlayBack = FindViewById<Button> (Resource.Id.PlayBack);
            Button BackToMandarin = FindViewById<Button> (Resource.Id.BackToMandarin);

            RecordVoice = FindViewById<Button> (Resource.Id.Record);
            StopRecord = FindViewById<Button> (Resource.Id.Stop);
            StockPlayer = MediaPlayer.Create(this, Resource.Raw.mother);

            _recorder = new MediaRecorder ();
            _player = new MediaPlayer ();

            //Click Event Handlers
            PlayStock.Click += delegate {
                StockPlayer.Start();
            };

            RecordVoice.Click += delegate {

                RecordVoice.Enabled = !RecordVoice.Enabled;
                StopRecord.Enabled = !StopRecord.Enabled;
                if (PlayBack.Enabled==true){
                    PlayBack.Enabled = false;
                }

                _recorder.SetAudioSource (AudioSource.Mic);
                _recorder.SetOutputFormat (OutputFormat.Mpeg4);
                _recorder.SetOutputFile(RecordPath);
                _recorder.SetAudioEncoder (AudioEncoder.Aac);

                _recorder.Prepare();
                _recorder.Start ();

            };

            //Stops recording
            StopRecord.Click += delegate {
                StopRecord.Enabled =! StopRecord.Enabled;

                if (PlayBack.Enabled==false){
                    PlayBack.Enabled = true;
                }

                _recorder.Stop ();
                _recorder.Reset ();

                /* For instant playback
                _player.SetDataSource (RecordPath);
                _player.Prepare ();
                _player.Start ();
                */
                RecordVoice.Enabled = !RecordVoice.Enabled;

            };

            PlayBack.Click += delegate {
                RecordPlayer = new MediaPlayer ();
                RecordPlayer.SetDataSource (RecordPath);
                RecordPlayer.Prepare ();
                RecordPlayer.Start ();

            };

            BackToMandarin.Click += delegate {
                HandleMandarinSelect ();
            };
        }