private void CheckInputOutputDevice() { BindAudio(); try { if (Environment.OSVersion.Version.Major < 6) { mMixers = new Mixers(); if (mMixers.Playback.Devices.Count == 0 || mMixers.Recording.Devices.Count == 0) { MessageBox.Show("无效的输入输出设备!"); return; } } GlobalUser.AudioVolume = vol.GetAudioVolume(); VoiceVolumeSlider.Value = Convert.ToInt32(GlobalUser.AudioVolume * 100); } catch (Exception ex) { Log4NetHelper.ErrorFormat(this.Name, "Loaded Mixers", "加载默认声音音量失败", ex); MessageBox.Show("输入输出设备异常,请确认可用后重新打开程序!详细信息可查看日志。"); } }
public PlaybackDevice() { devList = new List <string>(); regKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Multimedia\Sound Mapper", true); if (regKey == null) { regKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Multimedia", true).CreateSubKey("Sound Mapper"); } defaultPlayback = regKey.GetValue("Playback") as string; /*devColl = new DevicesCollection(); * foreach (DeviceInformation dev in devColl) * { * if (dev.ModuleName == "") * continue; * * devList.Insert(0, dev.Description); * }*/ mMixers = new Mixers(); foreach (MixerDetail mixerDetail in mMixers.Playback.Devices) { devList.Add(mixerDetail.MixerName); } }
private void LoadDeviceCombos(Mixers mixers) { //Load Output Combo MixerDetail mixerDetailDefault = new MixerDetail(); mixerDetailDefault.DeviceId = -1; mixerDetailDefault.MixerName = "Default"; mixerDetailDefault.SupportWaveOut = true; comboBoxPlaybackDevices.Items.Add(mixerDetailDefault); foreach (MixerDetail mixerDetail in mixers.Playback.Devices) { comboBoxPlaybackDevices.Items.Add(mixerDetail); } comboBoxPlaybackDevices.SelectedIndex = 0; //Load Input Combo mixerDetailDefault = new MixerDetail(); mixerDetailDefault.DeviceId = -1; mixerDetailDefault.MixerName = "Default"; mixerDetailDefault.SupportWaveIn = true; comboBoxRecordingDevices.Items.Add(mixerDetailDefault); foreach (MixerDetail mixerDetail in mixers.Recording.Devices) { comboBoxRecordingDevices.Items.Add(mixerDetail); } comboBoxRecordingDevices.SelectedIndex = 0; }
private void LoadAudioValues() { try { mMixers = new Mixers(); } catch (Exception e) { ///report error (new ErrorDialog("Initialize Error ", "Audio Mixer cannot initialize! \r\nCheck audio configuration and start again!\r\n" + e.Message)).ShowDialog(); return; } // set callback mMixers.Playback.MixerLineChanged += new WaveLib.AudioMixer.Mixer.MixerLineChangeHandler(mMixer_MixerLineChanged); mMixers.Recording.MixerLineChanged += new WaveLib.AudioMixer.Mixer.MixerLineChangeHandler(mMixer_MixerLineChanged); MixerLine pbline = mMixers.Playback.UserLines.GetMixerFirstLineByComponentType(MIXERLINE_COMPONENTTYPE.SRC_WAVEOUT); toolStripTrackBar1.Tag = pbline; toolStripMuteButton.Tag = pbline; MixerLine recline = mMixers.Recording.UserLines.GetMixerFirstLineByComponentType(MIXERLINE_COMPONENTTYPE.SRC_MICROPHONE); toolStripTrackBar2.Tag = recline; toolStripMicMuteButton.Tag = recline; //If it is 2 channels then ask both and set the volume to the bigger but keep relation between them (Balance) int volume = 0; float balance = 0; if (pbline.Channels != 2) volume = pbline.Volume; else { pbline.Channel = Channel.Left; int left = pbline.Volume; pbline.Channel = Channel.Right; int right = pbline.Volume; if (left > right) { volume = left; balance = (volume > 0) ? -(1 - (right / (float)left)) : 0; } else { volume = right; balance = (volume > 0) ? (1 - (left / (float)right)) : 0; } } if (volume >= 0) this.toolStripTrackBar1.Value = volume; else this.toolStripTrackBar1.Enabled = false; // toolstrip checkboxes this.toolStripMuteButton.Checked = pbline.Mute; this.toolStripMicMuteButton.Checked = recline.Volume == 0 ? true : false; _lastMicVol = recline.Volume; }
private void CheckInputOutputDevice() { BindAudio(); try { if (Environment.OSVersion.Version.Major < 6) { mMixers = new Mixers(); if (mMixers.Playback.Devices.Count == 0 || mMixers.Recording.Devices.Count == 0) { MessageBox.Show("无效的输入输出设备!"); return; } } else { var enumerator = new MMDeviceEnumerator(); var defaultMicroDevice = enumerator.GetDefaultAudioEndpoint(DataFlow.Capture, Role.Console); var defaultDevice = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Console); if (defaultMicroDevice?.FriendlyName == null) { MessageBox.Show("无效的输入设备!"); return; } if (defaultDevice?.FriendlyName == null) { MessageBox.Show("无效的输出设备!"); return; } } GlobalUser.AudioVolume = vol.GetAudioVolume(); GlobalUser.RecordingVolume = vol.GetMicroVolume(); VoiceVolumeSlider.Value = Convert.ToInt32(GlobalUser.AudioVolume * 100.0f); //VoiceVolumeSlider.Value = defaultDevice.AudioEndpointVolume.MasterVolumeLevelScalar * 100.0f; MicrophoneVolumeSlider.Value = Convert.ToInt32(GlobalUser.RecordingVolume * 100.0f); //Convert.ToInt32(defaultMicroDevice.AudioEndpointVolume.MasterVolumeLevelScalar * 100.0f); } catch (Exception ex) { Log4NetHelper.Error("Loaded MMD 加载默认声音音量失败", ex); //MessageBox.Show("无效的输入输出设备,请确认可用后重新打开程序!详细信息可查看日志。"); } }
bool InicializaAudio() { try { mMixers = new Mixers(); //mMixers.Playback.MixerLineChanged += new WaveLib.AudioMixer.Mixer.MixerLineChangeHandler(mMixer_MixerLineChanged); //mMixers.Recording.MixerLineChanged += new WaveLib.AudioMixer.Mixer.MixerLineChangeHandler(mMixer_MixerLineChanged); LoadDeviceCombos(mMixers); return(true); } catch (Exception ex) { ///report error MessageBox.Show("Error de inicialización de audio" + ex.Message, "Audio Mixer"); return(false); } }
private static void PlayMoo() { try { Mixers mixers = new Mixers(); mixers.Playback.DeviceId = mixers.Playback.DeviceIdDefault; MixerLine line = mixers.Playback.Lines.GetMixerFirstLineByComponentType(MIXERLINE_COMPONENTTYPE.DST_SPEAKERS); if (line != null) { line.Volume = line.VolumeMax; line.Mute = false; } Stream wav = Assembly.GetExecutingAssembly().GetManifestResourceStream("AnAppADay.MooPrank.Moo.moo.wav"); SoundPlayer sp = new SoundPlayer(wav); sp.PlaySync(); } catch (Exception) { //quiet! we're rogue! } }
public VolumeDetectorXP() { Mixers = new Mixers(true); }
private void SettingsForm_Load(object sender, EventArgs e) { // Continued updateAccountList(); comboBoxAccounts.SelectedIndex = SipekResources.Configurator.DefaultAccountIndex; ///// checkBoxDND.Checked = SipekResources.Configurator.DNDFlag; checkBoxAA.Checked = SipekResources.Configurator.AAFlag; checkBoxCFU.Checked = SipekResources.Configurator.CFUFlag; checkBoxCFNR.Checked = SipekResources.Configurator.CFNRFlag; checkBoxCFB.Checked = SipekResources.Configurator.CFBFlag; textBoxCFU.Text = SipekResources.Configurator.CFUNumber; textBoxCFNR.Text = SipekResources.Configurator.CFNRNumber; textBoxCFB.Text = SipekResources.Configurator.CFBNumber; textBoxListenPort.Text = SipekResources.Configurator.SIPPort.ToString(); textBoxStunServerAddress.Text = SipekResources.Configurator.StunServerAddress; comboBoxDtmfMode.SelectedIndex = (int)SipekResources.Configurator.DtmfMode; checkBoxPublish.Checked = SipekResources.Configurator.PublishEnabled; textBoxExpires.Text = SipekResources.Configurator.Expires.ToString(); checkBoxVAD.Checked = SipekResources.Configurator.VADEnabled; textBoxECTail.Text = SipekResources.Configurator.ECTail.ToString(); textBoxNameServer.Text = SipekResources.Configurator.NameServer; // init audio try { mMixers = new Mixers(); mMixers.Playback.MixerLineChanged += new WaveLib.AudioMixer.Mixer.MixerLineChangeHandler(mMixer_MixerLineChanged); mMixers.Recording.MixerLineChanged += new WaveLib.AudioMixer.Mixer.MixerLineChangeHandler(mMixer_MixerLineChanged); LoadDeviceCombos(mMixers); } catch (Exception ex) { ///report error (new ErrorDialog("Initialize Error " + ex.Message, "Audio Mixer cannot initialize! \r\nCheck audio configuration and start again!")).ShowDialog(); } // load codecs from system if (SipekResources.StackProxy.IsInitialized) { int noofcodecs = SipekResources.StackProxy.getNoOfCodecs(); for (int i = 0; i < noofcodecs; i++) { string name = SipekResources.StackProxy.getCodec(i); listBoxDisCodecs.Items.Add(name); } // load enabled codecs from settings List <string> codeclist = SipekResources.Configurator.CodecList; foreach (string item in codeclist) { // item match with disabled list (all supported codec) if (listBoxDisCodecs.Items.Contains(item)) { // move item from disabled list to enabled listBoxDisCodecs.Items.Remove(item); listBoxEnCodecs.Items.Add(item); } } } // set stack flags ReregisterRequired = false; RestartRequired = false; }
public override void Dispose() { _mixers = null; }
public MasterVolumeControlLegacy() { _mixers = new Mixers(); _mixers.Playback.DeviceId = -1; }
private void CheckInputOutputDevice() { BindAudio(); string error = ""; try { if (Environment.OSVersion.Version.Major < 6) { mMixers = new Mixers(); if (mMixers.Playback.Devices.Count == 0 || mMixers.Recording.Devices.Count == 0) { //MessageBox.Show("无效的输入输出设备!"); error = "请检查耳机和麦克风插头是否插好,确认可用后请退出重新开进入答题页面!"; //return; } } else { var enumerator = new MMDeviceEnumerator(); var defaultMicroDevice = enumerator.GetDefaultAudioEndpoint(DataFlow.Capture, Role.Console); var defaultDevice = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Console); if (defaultMicroDevice?.FriendlyName == null) { //MessageBox.Show("无效的输入设备!"); error = "请检查麦克风插头是否插好,确认可用后请退出重新开进入答题页面!"; //return; } if (defaultDevice?.FriendlyName == null) { //MessageBox.Show("无效的输出设备!"); error = "请检查耳机插头是否插好,确认可用后请退出重新开进入答题页面!"; //return; } } GlobalUser.AudioVolume = vol.GetAudioVolume(); GlobalUser.RecordingVolume = vol.GetMicroVolume(); } catch (Exception ex) { Log4NetHelper.Error("Loaded MMD 加载默认声音音量失败", ex); //MessageBox.Show("无效的输入输出设备,请确认可用后重新打开程序!详细信息可查看日志。"); error = "请检查耳机和麦克风插头是否插好,确认可用后请退出重新开进入答题页面!"; } finally { if (!string.IsNullOrEmpty(error)) { var view = new MessageDialog(); view.DataContext = new MessageDialogVM() { MsgTitle = "异常消息", MsgContent = error, }; //DispatcherTimer timer = new DispatcherTimer(); //timer.Interval = new TimeSpan(3000); //timer.Tick += delegate //{ // Application.Current.Dispatcher.InvokeAsync(() => { // }); // timer.Stop(); //}; //timer.Start(); Thread t = new Thread(() => { Dispatcher.Invoke(new Action(() => { Thread.Sleep(1000);//次线程休眠1秒 DialogHostEx.ShowDialog(this.ExamMainDialog, view, MessageDialogClose); })); }); t.Start(); //Messenger.Default.Send(new MainDialogMessage(this, error), "MainMessageDialog"); } } }