private void startRecording() { int captureDeviceId = getActiveCaptureDeviceId(); if (captureDeviceId >= 0) { try { btnRecord.Image = Properties.Resources.Speak_Off; soundRecorder = new SoundRecorder(captureDeviceId); soundRecorder.RecordingStoppedEvent += SoundRecorder_RecordingStoppedEvent; startTimerRecordingDuration(); soundRecorder.Start(); } catch (Exception ex) { stopTimerRecordingDuration(); soundRecorder = null; throw ex; } } else { MessageBoxManager.ShowMessageBoxError(MESSAGE_NO_CAPTUREDEVICE_FOUND_STRING); } }
private void SoundRecorder_RecordingStoppedEvent(object obj, NAudioWrapper.SoundRecordingStoppedEventArgs e) { if (e.SoundeData.Length >= 10000 /*more than ~ 500 ms of recording time*/) { if (client.IsConnected) { try { client.SendVoiceMessage(new VoiceMessage(broadcastClient, e.SoundeData)); } catch (Exception ex) { executeCodeOnUIThread(() => { MessageBoxManager.ShowMessageBoxError("Fehler beim übertragen der Broadcast-Nachricht.\n\n\n" + ex.StackTrace); }); } } else { executeCodeOnUIThread(() => { MessageBoxManager.ShowMessageBoxError("Ihre Broadcast-Nachricht konnte nicht versendet werden, da es keine Verbindung zum Server besteht."); }); } } }
private void soundPlayer_PlaybackStopped(object sender, EventArgs e) { lock (voiceMessageQueue) { if (voiceMessageQueue.Count > 0) // voicemessage data are in queue { VoiceMessage voiceMessage = voiceMessageQueue.Dequeue(); executeCodeOnUIThread(() => { showVoiceMessageReceivedBallonTip(voiceMessage); try { soundPlayer.Play(voiceMessage.Data); } catch (Exception ex) { Logger.log.Error(ex); MessageBoxManager.ShowMessageBoxError(ERROR_PLAYING_VOICEMESSAGE_STRING); } }); } else { soundPlayer.Stop(); soundPlayer = null; } } }
private void InitComboboxes() { try { var config = AppConfiguration.ReadConfig(); cbOutput.Items.Clear(); cbInput.Items.Clear(); var audioDeviceEnum = new AudioDeviceEnemerator(); var renderDevices = audioDeviceEnum.GetRenderDevices(); var captureDevices = audioDeviceEnum.GetCaptureDevices(); //Output cbOutput.Items.AddRange(renderDevices.ToArray()); DeviceInfo itemToSelect = cbOutput.Items.Cast <DeviceInfo>().ToList().Find(di => di.ProductGuid.Equals(config.RenderDevice.ProductGuid)); DeviceInfo noDeviceOutput = new DeviceInfo(); cbOutput.Items.Add(noDeviceOutput); // kein Gerät if (itemToSelect != null) { // select cbOutput.SelectedItem = itemToSelect; } else { cbOutput.SelectedItem = noDeviceOutput; } config.RenderDevice = cbOutput.SelectedItem as DeviceInfo; //Input cbInput.Items.AddRange(captureDevices.ToArray()); DeviceInfo itemToSelectInput = cbInput.Items.Cast <DeviceInfo>().ToList().Find(di => di.ProductGuid.Equals(config.CaptureDevice.ProductGuid)); if (itemToSelectInput != null) { // select cbInput.SelectedItem = itemToSelectInput; } else if (captureDevices.Count > 0) { cbInput.SelectedIndex = 0; } else { DeviceInfo noDeviceInput = new DeviceInfo(); cbInput.Items.Add(noDeviceInput); cbInput.SelectedItem = noDeviceInput; } config.CaptureDevice = cbInput.SelectedItem as DeviceInfo; AppConfiguration.SaveConfig(config); } catch (Exception ex) { MessageBoxManager.ShowMessageBoxErrorContactAdmin(ex.StackTrace); } }
private void btnRecord_MouseUp(object sender, MouseEventArgs e) { try { stopRecording(); } catch (Exception ex) { executeCodeOnUIThread(() => { MessageBoxManager.ShowMessageBoxError("Fehler bei der Aufnahme.\n\n\n" + ex.StackTrace); }); } }
private void TrayIcon_MouseClick(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { int captureDeviceId = getActiveCaptureDeviceId(); if (!client.IsConnected) { MessageBoxManager.ShowMessageBoxError("Voicebroadcast hat keine Verbindung zum Server!"); } else if (captureDeviceId >= 0) { setAppTaskbarIconState(true); showForm(); } else { MessageBoxManager.ShowMessageBoxError(MESSAGE_NO_CAPTUREDEVICE_FOUND_STRING); } } }
private void ok_Click(object sender, EventArgs e) { IPAddress ipTemp; if (IPAddress.TryParse(tbServerIP.Text, out ipTemp)) { Cursor.Current = Cursors.WaitCursor; try { AppConfiguration.SaveConfig( new AppConfiguration(tbServerIP.Text, (int)nudServerPort.Value, tbClientName.Text, cbInput.SelectedItem as DeviceInfo, cbOutput.SelectedItem as DeviceInfo)); Close(); } catch (Exception ex) { MessageBoxManager.ShowMessageBoxErrorContactAdmin(ex.StackTrace); } } else { MessageBoxManager.ShowMessageBoxError("Bitte geben Sie eine gültige IP-Adresse ein."); } }
private void Client_ClientVoiceMessageReceivedEvent(object obj, ClientVoiceMessageReceivedEventArgs e) { executeCodeOnUIThread(() => { try { int renderDeviceId = new AudioDeviceEnemerator().GetRenderDeviceIdByProductGUID(AppConfiguration.ReadConfig().RenderDevice.ProductGuid); if (renderDeviceId >= 0) { lock (voiceMessageQueue) { voiceMessageQueue.Enqueue(e.VoiceMessage); if (soundPlayer == null) { showVoiceMessageReceivedBallonTip(e.VoiceMessage); soundPlayer = new SoundPlayer(renderDeviceId); soundPlayer.PlaybackStoppedEvent += soundPlayer_PlaybackStopped; soundPlayer.Play(voiceMessageQueue.Dequeue().Data); } } } else { showVoiceMessageReceivedBallonTip(e.VoiceMessage); //MessageBoxManager.ShowMessageBoxError("Fehler beim Abspielen der Broadcast-Nachricht, da kein Ausgabegerät gefunden werden konnte."); } } catch (Exception ex) { MessageBoxManager.ShowMessageBoxError(ERROR_PLAYING_VOICEMESSAGE_STRING); Logger.log.Error(ex); } }); }