private async void Button_ClickSave(object sender, RoutedEventArgs e) { //make sure user enters a file name. does not need to be unique, as saveaudiotofile will create a unique file if the file name already exists bool validateName = ValidateFileName(); if (validateName) { //set values CreateVoiceMemo.DisplayName = displayName.Text; //unfortunately, we don't know the file name for sure until this is ran CreateVoiceMemo.FileName = await this._audioRecorder.SaveAudioToFile(); CreateVoiceMemo.FullFilePath = $"{Windows.ApplicationModel.Package.Current.InstalledLocation.Path}\\VoiceNotes"; CreateVoiceMemo.RecordingDuration = await _audioRecorder.GetAudioDuration(CreateVoiceMemo.FileName); CreateVoiceMemo.DateRecorded = _audioRecorder.GetDateRecorded(); DateTime timeRecorded = _audioRecorder.GetTimeRecorded(); // insert the voice memo's details into the database StoredProcedures.CreateVoiceNote(CreateVoiceMemo.FileName, CreateVoiceMemo.DisplayName, CreateVoiceMemo.RecordingDuration, CreateVoiceMemo.FullFilePath, CreateVoiceMemo.DateRecorded, timeRecorded); // refresh the voice memo list and hide our controls while showing the record button this.PopulateListOfVoiceMemos(); this.displayName.Text = ""; this.HideInitialControls(); this.startRecording.Visibility = Visibility.Visible; } else { DisplayEnterNameDialog(); } }
private void SaveRecording() { // make sure to run this in the main thread so that we can access our recording name box Utils.RunOnMainThread(async() => { if (StringUtils.IsNotBlank(this.RecordingNameBox.Text)) { try { string DisplayName = RecordingNameBox.Text; string FileName = await this.AudioRecorder.SaveAudioToFile(); string FullFilePath = $"{Windows.ApplicationModel.Package.Current.InstalledLocation.Path}\\VoiceNotes"; int RecordingDuration = await this.AudioRecorder.GetAudioDuration(FileName); DateTime DateRecorded = this.AudioRecorder.GetDateRecorded(); DateTime timeRecorded = this.AudioRecorder.GetTimeRecorded(); // insert the voice memo into the database StoredProcedures.CreateVoiceNote(FileName, DisplayName, RecordingDuration, FullFilePath, DateRecorded, DateRecorded); // clear our dynamic area and show the ui for the newly-recorded voice memo this.ClearArea(); RelativePanel voiceMemoPanel = VoiceMemoUIHelper.BuildVoiceMemoPanel(StoredProcedures.QueryLatestVoiceMemo(), this.AudioRecorder, () => Utils.RunOnMainThread(() => this.ClearArea())); // position the panel in the center of the panel RelativePanel.SetAlignHorizontalCenterWithPanel(voiceMemoPanel, true); RelativePanel.SetAlignVerticalCenterWithPanel(voiceMemoPanel, true); this.DynamicArea.Children.Add(voiceMemoPanel); } catch (Exception) { // TODO display an error message } } else { UIUtils.HighlightUIElement(this.RecordingNameBox); } }); }