public static TonePlayer GetInstance() { if (instance == null) { instance = new TonePlayer(); } return(instance); }
private async void btnRecord_Click(object sender, EventArgs e) { if (!Globals.getInstance().isRecording) { DriveSpaceManager.GetInstance().NumOfkinect = Globals.getInstance().viewerRecorderPairs.Count; if (DriveSpaceManager.GetInstance().ShouldStopRecording) { MessageBox.Show("Free disk space is too small. Please clean it first and then start recording again.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } if (DriveSpaceManager.GetInstance().ShouldWarnWhenRecording) { var result = MessageBox.Show("Free disk space is nearly used up. Are you sure you want to start recording now?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result == DialogResult.No) { return; } } else if (DriveSpaceManager.GetInstance().ShouldWarnBeforeRecording) { var result = MessageBox.Show($"You can only record for around {DriveSpaceManager.GetInstance().GetMinutesByAvailabeSpace()} minutes due to limited free space in the disk drive. Are you sure you want to start recording now?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if (result == DialogResult.No) { return; } } if (siteID.Length < 1) { MessageBox.Show("Please specify the testing site before recording.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // prepare the file-saving directory String folderName = DateTime.Now.ToString("yyyyMMddHHmmss"); String fullDirectory = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyVideos), "Kinect", folderName); // create the folder try { Directory.CreateDirectory(fullDirectory); } catch (Exception exception) { MessageBox.Show(exception.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // initialize the recorder foreach (var viewerRecorderPair in Globals.getInstance().viewerRecorderPairs) { viewerRecorderPair.Value.InitializeRecorder(fullDirectory, siteID); viewerRecorderPair.Value.StartRecord(); } // UI management lblRecordingTime.ForeColor = Color.Red; btnRecord.Text = "Stop Recording"; btnPreview.Enabled = false; Globals.getInstance().isRecording = true; dtStartRecordingTime = DateTime.Now; TonePlayer.GetInstance().PlayBeep(2000, 500, WaveFormType.SquareWave, 32000); } else { var result = MessageBox.Show("Sure to stop recording?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation); if (result == DialogResult.No) { return; } Globals.getInstance().isRecording = false; List <Task> tasks = new List <Task>(); foreach (var viewerRecorderPair in Globals.getInstance().viewerRecorderPairs) { tasks.Add(Task.Run(() => { viewerRecorderPair.Value.StopRecord(); })); } Globals.getInstance().hasStoppedRecordingButFlushing = true; await Task.WhenAll(tasks); Globals.getInstance().hasStoppedRecordingButFlushing = false; lblRecordingTime.ForeColor = Color.Gray; btnRecord.Text = "Record"; btnPreview.Enabled = true; } }