/// <summary>
        /// Stop recording and save the voice recording file
        /// </summary>
        /// <returns>file path to save audio file</returns>
        public string Save()
        {
            if ((_recorder.State == RecorderState.Idle) || (_recorder.State == RecorderState.Ready))
            {
                Console.WriteLine("AudioRecordService.Save : No need to cancel in State (" + _recorder.State + ") ");
                return(null);
            }

            try
            {
                // Stop recording and save the result in file
                _recorder.Commit();
                if (_recorder.State != RecorderState.Ready)
                {
                    Console.WriteLine("    AudioRecordService.Save state error");
                    // TODO : Handle error case
                    Toast.DisplayText("Fail to save audio file because of recording fw issue.");
                }

                string name  = filepath.Substring(filepath.IndexOf(' '));
                string final = name.Substring(0, name.IndexOf("_T_"));
                //string final = name.Substring(name.IndexOf("_T_"), name.Length - name.IndexOf("_T_"));
                numbering = Convert.ToInt32(final);
                Console.WriteLine("   ######  Voice File name - " + name + " --> final : " + final + " , numbering : " + numbering);
            }
            catch (Exception e)
            {
                HandleError("Commit", e);
            }

            return(filepath);
        }
Beispiel #2
0
        private void OnRecordButtonPressed(object sender, EventArgs e)
        {
            if (isRecording)
            {
                audioRecorder.Commit();
                audioRecorder.Unprepare();
                recordButton.ImageSource = ImageResources.RecordSymbol;
                sendButton.IsEnabled     = true;
                hint.Text = LocalizedStrings.RecordMessageHint;
            }
            else
            {
                DeleteTempFile();

                var internalStorage = StorageManager.Storages
                                      .First(s => s.StorageType == StorageArea.Internal)
                                      .GetAbsolutePath(DirectoryType.Others);
                voiceMessageTempPath = Path.Combine(internalStorage, Path.GetRandomFileName() + ".3gp");

                audioRecorder.Prepare();
                audioRecorder.Start(voiceMessageTempPath);
                recordButton.ImageSource = ImageResources.StopSymbol;
                sendButton.IsEnabled     = false;
                hint.Text = LocalizedStrings.StopRecordMessageHint;
            }

            isRecording = !isRecording;
        }
        /// <summary>
        /// Stops recording and closes the audio file.
        /// </summary>
        /// <exception cref="InvalidOperationException">If it is called before start()</exception>
        public void Stop()
        {
            if (_recorder == null)
            {
                throw new InvalidOperationException("The recorder has not been prepared.");
            }

            _recorder.Commit();
        }
        /// <summary>
        /// Stops recording.
        /// Saves the file.
        /// Invokes "VoiceRecorderStopped" to other application's modules.
        /// </summary>
        public void StopVoiceRecording()
        {
            try
            {
                _recorder.Commit();

                using (var databaseConnector = new DatabaseConnector())
                {
                    databaseConnector.ErrorOccurred += OnDatabaseError;
                    databaseConnector.UpdateDatabase();
                }

                RecordingSaved?.Invoke(this, Path.GetFileName(_recordingPath));
                VoiceRecorderStopped?.Invoke(this, new EventArgs());
            }
            catch (Exception exception)
            {
                ErrorHandler(exception.Message);
            }
        }