Exemplo n.º 1
0
    public VolumeHandler(int[] volumeTable)
    {
      if (GUIGraphicsContext.DeviceAudioConnected > 0)
      {
        bool isDigital;
        bool hideWindowsOSD;

        using (Settings reader = new MPSettings())
        {
          int levelStyle = reader.GetValueAsInt("volume", "startupstyle", 0);

          if (levelStyle == 0)
          {
            _startupVolume = Math.Max(0, Math.Min(65535, reader.GetValueAsInt("volume", "lastknown", 52428)));
          }

          if (levelStyle == 1)
          {
          }

          if (levelStyle == 2)
          {
            _startupVolume = Math.Max(0, Math.Min(65535, reader.GetValueAsInt("volume", "startuplevel", 52428)));
          }

          isDigital = reader.GetValueAsBool("volume", "digital", false);

          _showVolumeOSD = reader.GetValueAsBool("volume", "defaultVolumeOSD", true);

          hideWindowsOSD = reader.GetValueAsBool("volume", "hideWindowsOSD", false);
        }

        try
        {
          _mixer = new Mixer.Mixer();
          _mixer.Open(0, isDigital);
          _volumeTable = volumeTable;
          _mixer.ControlChanged += mixer_ControlChanged;
        }
        catch (Exception ex)
        {
          Log.Error("VolumeHandler: Mixer exception when init {0}", ex);
        }

        if (OSInfo.OSInfo.Win8OrLater() && hideWindowsOSD)
        {
          try
          {
            bool tempShowVolumeOSD = _showVolumeOSD;

            _showVolumeOSD = false;
            
            VolumeOSD = new HideVolumeOSD.HideVolumeOSDLib(IsMuted);
            VolumeOSD.HideOSD();

            _showVolumeOSD = tempShowVolumeOSD;
          }
          catch { }
        }
      }
      else
      {
        _volumeTable = volumeTable;
      }
    }
Exemplo n.º 2
0
        public VolumeHandler(int[] volumeTable)
        {
            if (OSInfo.OSInfo.Win10OrLater())
            {
                if (_MMdeviceEnumerator == null)
                {
                    _MMdeviceEnumerator = new MMDeviceEnumerator();
                }

                var mMdeviceList = _MMdeviceEnumerator.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active);

                if (mMdeviceList.Count > 0)
                {
                    var mMdevice = _MMdeviceEnumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
                    if (mMdevice != null)
                    {
                        using (Settings reader = new MPSettings())
                        {
                            int levelStyle = reader.GetValueAsInt("volume", "startupstyle", 0);

                            if (levelStyle == 0)
                            {
                                _startupVolume = Math.Max(0, Math.Min(65535, reader.GetValueAsInt("volume", "lastknown", 52428)));
                            }

                            if (levelStyle == 1)
                            {
                            }

                            if (levelStyle == 2)
                            {
                                _startupVolume = Math.Max(0, Math.Min(65535, reader.GetValueAsInt("volume", "startuplevel", 52428)));
                            }

                            IsDigital = reader.GetValueAsBool("volume", "digital", false);

                            _showVolumeOSD = reader.GetValueAsBool("volume", "defaultVolumeOSD", true);

                            hideWindowsOSD = reader.GetValueAsBool("volume", "hideWindowsOSD", false);
                        }

                        try
                        {
                            _volumeTable = volumeTable;
                            _mixer10     = new Mixer.Mixer10();
                            _mixer10.Open(0, IsDigital, volumeTable);
                        }
                        catch (Exception ex)
                        {
                            Log.Error("VolumeHandler: Mixer exception during init {0}", ex);
                        }

                        if (OSInfo.OSInfo.Win8OrLater() && hideWindowsOSD)
                        {
                            try
                            {
                                bool tempShowVolumeOSD = _showVolumeOSD;

                                _showVolumeOSD = true;

                                VolumeOSD = new HideVolumeOSD.HideVolumeOSDLib(IsMuted);
                                VolumeOSD.HideOSD();

                                _showVolumeOSD = tempShowVolumeOSD;
                            }
                            catch
                            {
                            }
                        }
                    }
                }
                else
                {
                    _volumeTable = volumeTable;
                }
            }
            else
            {
                if (GUIGraphicsContext.DeviceAudioConnected > 0)
                {
                    using (Settings reader = new MPSettings())
                    {
                        int levelStyle = reader.GetValueAsInt("volume", "startupstyle", 0);

                        if (levelStyle == 0)
                        {
                            _startupVolume = Math.Max(0, Math.Min(65535, reader.GetValueAsInt("volume", "lastknown", 52428)));
                        }

                        if (levelStyle == 1)
                        {
                        }

                        if (levelStyle == 2)
                        {
                            _startupVolume = Math.Max(0, Math.Min(65535, reader.GetValueAsInt("volume", "startuplevel", 52428)));
                        }

                        IsDigital = reader.GetValueAsBool("volume", "digital", false);

                        _showVolumeOSD = reader.GetValueAsBool("volume", "defaultVolumeOSD", true);

                        hideWindowsOSD = reader.GetValueAsBool("volume", "hideWindowsOSD", false);
                    }

                    try
                    {
                        _mixer = new Mixer.Mixer();
                        _mixer.Open(0, IsDigital);
                        _volumeTable           = volumeTable;
                        _mixer.ControlChanged += mixer_ControlChanged;
                    }
                    catch (Exception ex)
                    {
                        Log.Error("VolumeHandler: Mixer exception when init {0}", ex);
                    }

                    if (OSInfo.OSInfo.Win8OrLater() && hideWindowsOSD)
                    {
                        try
                        {
                            bool tempShowVolumeOSD = _showVolumeOSD;

                            _showVolumeOSD = true;

                            VolumeOSD = new HideVolumeOSD.HideVolumeOSDLib(IsMuted);
                            VolumeOSD.HideOSD();

                            _showVolumeOSD = tempShowVolumeOSD;
                        }
                        catch
                        {
                        }
                    }
                }
                else
                {
                    _volumeTable = volumeTable;
                }
            }
        }
        public VolumeHandler(int[] volumeTable)
        {
            if (GUIGraphicsContext.DeviceAudioConnected > 0)
            {
                bool isDigital;
                bool hideWindowsOSD;

                using (Settings reader = new MPSettings())
                {
                    int levelStyle = reader.GetValueAsInt("volume", "startupstyle", 0);

                    if (levelStyle == 0)
                    {
                        _startupVolume = Math.Max(0, Math.Min(65535, reader.GetValueAsInt("volume", "lastknown", 52428)));
                    }

                    if (levelStyle == 1)
                    {
                    }

                    if (levelStyle == 2)
                    {
                        _startupVolume = Math.Max(0, Math.Min(65535, reader.GetValueAsInt("volume", "startuplevel", 52428)));
                    }

                    isDigital = reader.GetValueAsBool("volume", "digital", false);

                    _showVolumeOSD = reader.GetValueAsBool("volume", "defaultVolumeOSD", true);

                    hideWindowsOSD = reader.GetValueAsBool("volume", "hideWindowsOSD", false);
                }

                try
                {
                    _mixer = new Mixer.Mixer();
                    _mixer.Open(0, isDigital);
                    _volumeTable           = volumeTable;
                    _mixer.ControlChanged += mixer_ControlChanged;
                }
                catch (Exception ex)
                {
                    Log.Error("VolumeHandler: Mixer exception when init {0}", ex);
                }

                if (OSInfo.OSInfo.Win8OrLater() && hideWindowsOSD)
                {
                    try
                    {
                        bool tempShowVolumeOSD = _showVolumeOSD;

                        _showVolumeOSD = false;

                        VolumeOSD = new HideVolumeOSD.HideVolumeOSDLib(IsMuted);
                        VolumeOSD.HideOSD();

                        _showVolumeOSD = tempShowVolumeOSD;
                    }
                    catch { }
                }
            }
            else
            {
                _volumeTable = volumeTable;
            }
        }