Esempio n. 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);
                }
            }
        }
Esempio n. 2
0
        private MixerNativeMethods.MixerControlDetails GetControl(MixerComponentType componentType,
                                                                  MixerControlType controlType)
        {
            MixerNativeMethods.MixerLine mixerLine = new MixerNativeMethods.MixerLine(componentType);

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

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

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

                return(new MixerNativeMethods.MixerControlDetails(mixerControl.ControlId));
            }
        }
Esempio n. 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);
        }
Esempio n. 4
0
        private MixerNativeMethods.MixerControlDetails GetControl(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.GetControl.1");
                }

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

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

                    return(new MixerNativeMethods.MixerControlDetails(mixerControl.ControlId));
                }
            }
            catch (Exception ex)
            {
                // Catch exception when audio device is disconnected
                Log.Error("Mixer: GetControl {0}", ex.Message);
            }
            return(null);
        }