Example #1
0
        private void SetValue(MixerComponentType componentType, MixerControlType controlType, int controlValue)
        {
            MixerNativeMethods.MixerLine mixerLine = new MixerNativeMethods.MixerLine(componentType);

            if (MixerNativeMethods.mixerGetLineInfoA(_handle, ref mixerLine, MixerLineFlags.ComponentType) != MixerError.None)
            {
                throw new InvalidOperationException("Mixer.SetValue.1");
            }

            using (
                MixerNativeMethods.MixerLineControls mixerLineControls =
                    new MixerNativeMethods.MixerLineControls(mixerLine.LineId, controlType))
            {
                if (MixerNativeMethods.mixerGetLineControlsA(_handle, mixerLineControls, MixerLineControlFlags.OneByType) !=
                    MixerError.None)
                {
                    throw new InvalidOperationException("Mixer.SetValue.2");
                }

                MixerNativeMethods.MixerControl mixerControl =
                    (MixerNativeMethods.MixerControl)
                    Marshal.PtrToStructure(mixerLineControls.Data, typeof(MixerNativeMethods.MixerControl));

                using (
                    MixerNativeMethods.MixerControlDetails mixerControlDetails =
                        new MixerNativeMethods.MixerControlDetails(mixerControl.ControlId))
                {
                    Marshal.WriteInt32(mixerControlDetails.Data, controlValue);
                    MixerNativeMethods.mixerSetControlDetails(_handle, mixerControlDetails, 0);
                }
            }
        }
    private void SetValue(MixerNativeMethods.MixerControlDetails control, int value)
    {
      if (control == null)
      {
        return;
      }

      Marshal.WriteInt32(control.Data, value);
      MixerNativeMethods.mixerSetControlDetails(_handle, control, 0);
    }
Example #3
0
        private object GetValue(MixerComponentType componentType, MixerControlType controlType)
        {
            try
            {
                MixerNativeMethods.MixerLine mixerLine = new MixerNativeMethods.MixerLine(componentType);

                if (MixerNativeMethods.mixerGetLineInfoA(_handle, ref mixerLine, MixerLineFlags.ComponentType) !=
                    MixerError.None)
                {
                    throw new InvalidOperationException("Mixer.OpenControl.1");
                }

                using (
                    MixerNativeMethods.MixerLineControls mixerLineControls =
                        new MixerNativeMethods.MixerLineControls(mixerLine.LineId, controlType))
                {
                    MixerNativeMethods.mixerGetLineControlsA(_handle, mixerLineControls, MixerLineControlFlags.OneByType);
                    MixerNativeMethods.MixerControl mixerControl =
                        (MixerNativeMethods.MixerControl)
                        Marshal.PtrToStructure(mixerLineControls.Data, typeof(MixerNativeMethods.MixerControl));

                    using (
                        MixerNativeMethods.MixerControlDetails mixerControlDetails =
                            new MixerNativeMethods.MixerControlDetails(mixerControl.ControlId))
                    {
                        MixerNativeMethods.mixerGetControlDetailsA(_handle, mixerControlDetails, 0);

                        return(Marshal.ReadInt32(mixerControlDetails.Data));
                    }
                }
            }
            catch (Exception ex)
            {
                // Catch exception when audio device is disconnected
                Log.Error("Mixer: GetValue {0}", ex.Message);
            }
            // Set Volume to 30000 when audio recover
            return(30000);
        }
Example #4
0
    private void SetValue(MixerComponentType componentType, MixerControlType controlType, int controlValue)
    {
      MixerNativeMethods.MixerLine mixerLine = new MixerNativeMethods.MixerLine(componentType);

      if (MixerNativeMethods.mixerGetLineInfoA(_handle, ref mixerLine, MixerLineFlags.ComponentType) != MixerError.None)
      {
        throw new InvalidOperationException("Mixer.SetValue.1");
      }

      using (
        MixerNativeMethods.MixerLineControls mixerLineControls =
          new MixerNativeMethods.MixerLineControls(mixerLine.LineId, controlType))
      {
        if (MixerNativeMethods.mixerGetLineControlsA(_handle, mixerLineControls, MixerLineControlFlags.OneByType) !=
            MixerError.None)
        {
          throw new InvalidOperationException("Mixer.SetValue.2");
        }

        MixerNativeMethods.MixerControl mixerControl =
          (MixerNativeMethods.MixerControl)
          Marshal.PtrToStructure(mixerLineControls.Data, typeof (MixerNativeMethods.MixerControl));

        using (
          MixerNativeMethods.MixerControlDetails mixerControlDetails =
            new MixerNativeMethods.MixerControlDetails(mixerControl.ControlId))
        {
          Marshal.WriteInt32(mixerControlDetails.Data, controlValue);
          MixerNativeMethods.mixerSetControlDetails(_handle, mixerControlDetails, 0);
        }
      }
    }
Example #5
0
    private object GetValue(MixerComponentType componentType, MixerControlType controlType)
    {
      try
      {
        MixerNativeMethods.MixerLine mixerLine = new MixerNativeMethods.MixerLine(componentType);

        if (MixerNativeMethods.mixerGetLineInfoA(_handle, ref mixerLine, MixerLineFlags.ComponentType) !=
            MixerError.None)
        {
          throw new InvalidOperationException("Mixer.OpenControl.1");
        }

        using (
          MixerNativeMethods.MixerLineControls mixerLineControls =
            new MixerNativeMethods.MixerLineControls(mixerLine.LineId, controlType))
        {
          MixerNativeMethods.mixerGetLineControlsA(_handle, mixerLineControls, MixerLineControlFlags.OneByType);
          MixerNativeMethods.MixerControl mixerControl =
            (MixerNativeMethods.MixerControl)
              Marshal.PtrToStructure(mixerLineControls.Data, typeof(MixerNativeMethods.MixerControl));

          using (
            MixerNativeMethods.MixerControlDetails mixerControlDetails =
              new MixerNativeMethods.MixerControlDetails(mixerControl.ControlId))
          {
            MixerNativeMethods.mixerGetControlDetailsA(_handle, mixerControlDetails, 0);

            return Marshal.ReadInt32(mixerControlDetails.Data);
          }
        }
      }
      catch (Exception)
      {
        // Catch exception when audio device is disconnected
      }
      // Set Volume to 30000 when audio recover
      return 30000;
    }