void StartAudioThread(bool record) { if (record) { if (Recorder == null) { RecordAudio tmp = new RecordAudio(this); Recorder = tmp; // use temp so audio thread doesn't use before ready } RecordingActive = true; AudioEvent.Set(); } if (AudioThread != null && AudioThread.IsAlive) return; AudioThread = new Thread(new ThreadStart(RunAudioThread)); AudioThread.Name = "Voice Thread"; ThreadRunning = true; AudioThread.Start(); }
public void ResetDevices() { // kill thread if (AudioThread != null) { ThreadRunning = false; AudioEvent.Set(); AudioThread.Join(2000); AudioThread = null; } // deconstruct all record/play streams if (Recorder != null) { Recorder.Dispose(); Recorder = null; } Players.ForEach(p => p.Dispose()); Players.SafeClear(); // will auto be recreated }