示例#1
0
        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("输入输出设备异常,请确认可用后重新打开程序!详细信息可查看日志。");
            }
        }
示例#2
0
        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("无效的输入输出设备,请确认可用后重新打开程序!详细信息可查看日志。");
            }
        }
示例#3
0
        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");
                }
            }
        }