/// <summary> /// Builds a relative panel containing the details of a voice memo /// </summary> /// <param name="voiceMemo">The voice memo to build the panel for</param> /// <param name="audioRecorder">The object that will play the voice memo's audio</param> /// <param name="DeleteCallBack">the callback function for when the voice memo's delete button is clicked</param> /// <returns></returns> public static RelativePanel BuildVoiceMemoPanel(VoiceMemo voiceMemo, AudioRecorder audioRecorder, Action DeleteCallBack = null) { var panel = new RelativePanel(); panel.Margin = new Thickness(0, 10, 0, 10); var ellipse = BuildMemoEllipse(); var titleBlock = BuildTitleBlock(voiceMemo); var durationBlock = BuildDurationBlock(voiceMemo); var dateRecordedBlock = BuildDateRecordedBlock(voiceMemo); var deleteButton = BuildDeleteButton(voiceMemo, audioRecorder, DeleteCallBack); var playbackButton = BuildPlayBackButton(voiceMemo, audioRecorder); panel.Children.Add(ellipse); panel.Children.Add(titleBlock); panel.Children.Add(durationBlock); panel.Children.Add(dateRecordedBlock); panel.Children.Add(deleteButton); panel.Children.Add(playbackButton); // position the elements within the panel RelativePanel.SetRightOf(titleBlock, ellipse); RelativePanel.SetAlignVerticalCenterWith(titleBlock, ellipse); RelativePanel.SetBelow(durationBlock, titleBlock); RelativePanel.SetAlignLeftWith(durationBlock, titleBlock); RelativePanel.SetBelow(dateRecordedBlock, durationBlock); RelativePanel.SetAlignLeftWith(dateRecordedBlock, durationBlock); RelativePanel.SetBelow(deleteButton, dateRecordedBlock); RelativePanel.SetAlignBottomWithPanel(deleteButton, true); RelativePanel.SetAlignLeftWithPanel(deleteButton, true); RelativePanel.SetBelow(playbackButton, dateRecordedBlock); RelativePanel.SetAlignBottomWithPanel(playbackButton, true); RelativePanel.SetAlignRightWithPanel(playbackButton, true); return(panel); }
/// <summary> /// Builds and returns a text block whose contents are the <see cref="VoiceMemo.RecordingDuration"/> of the passed <paramref name="VoiceMemoToAdd"/>. /// </summary> /// <param name="VoiceMemoToAdd"></param> /// <returns></returns> private static TextBlock BuildDurationBlock(VoiceMemo VoiceMemoToAdd) { var durationBlock = new TextBlock(); durationBlock.Text = $"Duration: {TimeSpan.FromSeconds(VoiceMemoToAdd.RecordingDuration):mm\\:ss}"; return(durationBlock); }
/// <summary> /// Plays back the passed <paramref name="VoiceMemoToPlay"/> using the passed <paramref name="audioRecorder"/> /// </summary> /// <param name="VoiceMemoToPlay"></param> /// <param name="audioRecorder"></param> private static async void PlayVoiceMemo(VoiceMemo VoiceMemoToPlay, AudioRecorder audioRecorder) { //don't let playback if in recording session if (!audioRecorder.IsRecording) { await audioRecorder.PlayFromDisk(VoiceMemoToPlay.FileName); } }
/// <summary> /// Builds and returns text block for the <paramref name="VoiceMemoToAdd"/>. The text of this block is the <see cref="VoiceMemo.DisplayName"/> of the VoiceMemoToAdd. /// </summary> /// <param name="VoiceMemoToAdd"></param> /// <returns></returns> private static TextBlock BuildTitleBlock(VoiceMemo VoiceMemoToAdd) { var titleBlock = new TextBlock(); titleBlock.FontWeight = FontWeights.Bold; titleBlock.Text = VoiceMemoToAdd.DisplayName; return(titleBlock); }
/// <summary> /// Builds and returns a button that plays back the passed <paramref name="VoiceMemoToAdd"/> using the passed <paramref name="audioRecorder"/> /// </summary> /// <param name="VoiceMemoToAdd"></param> /// <param name="audioRecorder"></param> /// <returns></returns> private static Button BuildPlayBackButton(VoiceMemo VoiceMemoToAdd, AudioRecorder audioRecorder) { var playbackButton = new Button(); playbackButton.Content = "Playback"; playbackButton.Click += (sender, arguments) => PlayVoiceMemo(VoiceMemoToAdd, audioRecorder); return(playbackButton); }
/// <summary> /// Builds and returns a button that deletes the passed <paramref name="VoiceMemoToAdd"/> from the database and the file system /// </summary> /// <param name="VoiceMemoToAdd"></param> /// <param name="audioRecorder"></param> /// <param name="Callback"></param> /// <returns></returns> private static Button BuildDeleteButton(VoiceMemo VoiceMemoToAdd, AudioRecorder audioRecorder, Action Callback = null) { var deleteButton = new Button(); deleteButton.Content = "Delete"; deleteButton.Click += (sender, arguments) => DeleteVoiceMemoAsync(VoiceMemoToAdd, audioRecorder, Callback); return(deleteButton); }
/// <summary> /// Builds and returns a text block whose text is the <see cref="VoiceMemo.DateRecorded"/> of the passed <paramref name="VoiceMemoToAdd"/>. /// </summary> /// <param name="VoiceMemoToAdd"></param> /// <returns></returns> private static TextBlock BuildDateRecordedBlock(VoiceMemo VoiceMemoToAdd) { var dateRecordedBlock = new TextBlock(); dateRecordedBlock.Margin = new Thickness(0, 0, 0, 20); dateRecordedBlock.Text = VoiceMemoToAdd.DateRecorded.ToShortDateString(); return(dateRecordedBlock); }
/// <summary> /// Stops playback of the passed <paramref name="audioRecorder"/>, deletes the passed <paramref name="VoiceMemoToDelete"/> from the database and the file system, and calls the passed <paramref name="Callback"/> if it's not null /// </summary> /// <param name="VoiceMemoToDelete"></param> /// <param name="audioRecorder"></param> /// <param name="Callback"></param> /// <returns></returns> private static async Task DeleteVoiceMemoAsync(VoiceMemo VoiceMemoToDelete, AudioRecorder audioRecorder, Action Callback = null) { if (await DisplayDeleteFileDialog()) { //stop playing and dispose stream audioRecorder.StopPlaybackMedia(); audioRecorder.DisposeStream(); //delete file and from database and file system audioRecorder.DeleteFile(VoiceMemoToDelete.FileName); StoredProcedures.DeleteVoiceNote(VoiceMemoToDelete.VoiceMemoID); // call the callback function if it's not null Callback?.Invoke(); } }
public static VoiceMemo QueryLatestVoiceMemo() { VoiceMemo memo = new VoiceMemo(); using (SqliteConnection connection = OpenDatabase()) { using (SqliteCommand command = connection.CreateCommand()) { command.CommandText = "SELECT * FROM TVoiceMemos WHERE voiceMemoID = (SELECT MAX(voiceMemoID) From TVoiceMemos)"; SqliteDataReader reader = command.ExecuteReader(); reader.Read(); memo = VoiceMemo.FromDataRow(reader); reader.Close(); } } return(memo); }
public static List <VoiceMemo> QueryAllVoiceMemos() { List <VoiceMemo> voiceMemos = new List <VoiceMemo>(); string query = @"Select voiceMemoID, fileName, displayName, recordingDuration, filePath, recordDate, recordTime From TVoiceMemos ORDER BY recordDate, recordTime;"; using (SqliteConnection connection = OpenDatabase()) { SqliteCommand command = connection.CreateCommand(); command.CommandText = query; using (SqliteDataReader reader = command.ExecuteReader()) { while (reader.Read()) { voiceMemos.Add(VoiceMemo.FromDataRow(reader)); } } } return(voiceMemos); }
private void BuildMemoPanel(VoiceMemo VoiceMemoToAdd) { this.VoiceNoteList.Children.Add(VoiceMemoUIHelper.BuildVoiceMemoPanel(VoiceMemoToAdd, this._audioRecorder, PopulateListOfVoiceMemos)); }