Exemple #1
0
 public override void EndInterruption(AVAudioRecorder recorder)
 {
     if (cbEndInterruption != null)
     {
         cbEndInterruption(recorder, EventArgs.Empty);
     }
 }
Exemple #2
0
 public override void EncoderError(AVAudioRecorder recorder, NSError error)
 {
     if (cbEncoderError != null)
     {
         cbEncoderError(recorder, new AVErrorEventArgs(error));
     }
 }
Exemple #3
0
 public override void FinishedRecording(AVAudioRecorder recorder, bool flag)
 {
     if (cbFinishedRecording != null)
     {
         cbFinishedRecording(recorder, new AVStatusEventArgs(flag));
     }
 }
Exemple #4
0
        public static AVAudioRecorder Create(NSUrl url, AVAudioFormat format, out NSError error)
        {
            if (format == null)
            {
                throw new ArgumentNullException(nameof(format));
            }
            error = null;
            try {
                AVAudioRecorder r = new AVAudioRecorder(url, format, out error);
                if (r.Handle == IntPtr.Zero)
                {
                    return(null);
                }

                return(r);
            } catch {
                return(null);
            }
        }
Exemple #5
0
        public static AVAudioRecorder Create(NSUrl url, AudioSettings settings, out NSError error)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }
            error = null;
            try {
                AVAudioRecorder r = new AVAudioRecorder(url, settings, out error);
                if (r.Handle == IntPtr.Zero)
                {
                    return(null);
                }

                return(r);
            } catch {
                return(null);
            }
        }
		public bool RecordAudio()
		{
			try {
				var audioSession = AVFoundation.AVAudioSession.SharedInstance ();
				var err = audioSession.SetCategory (AVFoundation.AVAudioSessionCategory.PlayAndRecord);
				if (err != null) {
					return false;
				}
				err = audioSession.SetActive (true);
				if (err != null) {
					return false;
				}
				string directoryname = string.Empty;

				try {
					var documents =
						Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments);
					directoryname = System.IO.Path.Combine (documents, "PurposeColor/Audio");
					System.IO.Directory.CreateDirectory(directoryname);
				} catch (Exception ex) {
					var test = ex.Message;
				}

			    fileName = string.Format ("Audio{0}.wav", DateTime.Now.ToString ("yyyyMMddHHmmss"));
			    audioFilePath = System.IO.Path.Combine (directoryname, fileName);

				url = Foundation.NSUrl.FromFilename (audioFilePath);

				//set up the NSObject Array of values that will be combined with the keys to make the NSDictionary
				Foundation.NSObject[] values = new NSObject[] {
					NSNumber.FromFloat (44100.0f), //Sample Rate
					NSNumber.FromInt32 ((int)AudioToolbox.AudioFormatType.LinearPCM), //AVFormat
					NSNumber.FromInt32 (1), //Channels
					NSNumber.FromInt32 (16) //PCMBitDepth
				};
				
				//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
				};
				//Set Settings with the Values and Keys to create the NSDictionary
				settings = NSDictionary.FromObjectsAndKeys (values, keys);
				var error  = new NSError();
				//Set recorder parameters
				recorder = AVAudioRecorder.Create (url, new AudioSettings (settings), out error);
				//Set Recorder to Prepare To Record
				recorder.PrepareToRecord ();
				recorder.Record ();

				return true;
			}
			catch (Exception ex) 
			{
				var tt = ex.Message;
				return false;
			}

		}