Beispiel #1
0
        void SetMute(bool flag)
        {
            MIXERCONTROLDETAILS         muteCtl = new MIXERCONTROLDETAILS();
            MIXERCONTROLDETAILS_BOOLEAN muteVal = new MIXERCONTROLDETAILS_BOOLEAN();

            muteVal.Value = flag ? 1 : 0;

            Debug.WriteLine("MixerAPI.SetMute:" + flag.ToString());

            IntPtr mutePtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(new MIXERCONTROLDETAILS_BOOLEAN()));

            Marshal.StructureToPtr(muteVal, mutePtr, false);

            muteCtl.StructSize      = (uint)Marshal.SizeOf(new MIXERCONTROLDETAILS());
            muteCtl.ControlID       = _muteID;
            muteCtl.Channels        = 1;
            muteCtl.MultipleItems   = 0;
            muteCtl.DetailsItemSize = (uint)Marshal.SizeOf(new MIXERCONTROLDETAILS_BOOLEAN());
            muteCtl.DetailsPointer  = mutePtr;

            uint mmresult = mixerSetControlDetails(_hMixer, ref muteCtl,
                                                   MIXER_OBJECTF.HMIXER, MIXER_GETCONTROLDETAILSF.VALUE);

            Marshal.FreeCoTaskMem(mutePtr);

            if (mmresult != (uint)MMRESULT.MMSYSERR_NOERROR)
            {
                throw new Exception("mixerSetControlDetails" + mmresult.ToString());
            }
        }
Beispiel #2
0
        bool IsMute()
        {
            MIXERCONTROLDETAILS muteCtl = new MIXERCONTROLDETAILS();
            IntPtr mutePtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(new MIXERCONTROLDETAILS_BOOLEAN()));

            muteCtl.StructSize      = (uint)Marshal.SizeOf(new MIXERCONTROLDETAILS());
            muteCtl.ControlID       = _muteID;
            muteCtl.Channels        = 1;
            muteCtl.MultipleItems   = 0;
            muteCtl.DetailsItemSize = (uint)Marshal.SizeOf(new MIXERCONTROLDETAILS_BOOLEAN());
            muteCtl.DetailsPointer  = mutePtr;

            uint mmresult = mixerGetControlDetails(_hMixer, ref muteCtl,
                                                   MIXER_OBJECTF.HMIXER, MIXER_GETCONTROLDETAILSF.VALUE);

            if (mmresult != (uint)MMRESULT.MMSYSERR_NOERROR)
            {
                Marshal.FreeCoTaskMem(mutePtr);
                throw new MixerException("mixerGetControlDetails", mmresult);
            }

            MIXERCONTROLDETAILS_BOOLEAN muteInfo
                = (MIXERCONTROLDETAILS_BOOLEAN)Marshal.PtrToStructure(mutePtr,
                                                                      typeof(MIXERCONTROLDETAILS_BOOLEAN));

            Marshal.FreeCoTaskMem(mutePtr);

            Debug.WriteLine("MixerAPI.IsMuteret:" + muteInfo.Value.ToString());

            return(muteInfo.Value > 0);
        }
Beispiel #3
0
        void SetMute(bool flag)
        {
            MIXERCONTROLDETAILS muteCtl = new MIXERCONTROLDETAILS();
            MIXERCONTROLDETAILS_BOOLEAN muteVal = new MIXERCONTROLDETAILS_BOOLEAN();
            muteVal.Value = flag ? 1 : 0;

            Debug.WriteLine("MixerAPI.SetMute:" + flag.ToString());

            IntPtr mutePtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(new MIXERCONTROLDETAILS_BOOLEAN()));
            Marshal.StructureToPtr(muteVal, mutePtr, false);

            muteCtl.StructSize = (uint)Marshal.SizeOf(new MIXERCONTROLDETAILS());
            muteCtl.ControlID = _muteID;
            muteCtl.Channels = 1;
            muteCtl.MultipleItems = 0;
            muteCtl.DetailsItemSize = (uint)Marshal.SizeOf(new MIXERCONTROLDETAILS_BOOLEAN());
            muteCtl.DetailsPointer = mutePtr;

            uint mmresult = mixerSetControlDetails(_hMixer, ref muteCtl,
                MIXER_OBJECTF.HMIXER, MIXER_GETCONTROLDETAILSF.VALUE);
            Marshal.FreeCoTaskMem(mutePtr);

            if (mmresult != (uint)MMRESULT.MMSYSERR_NOERROR)
            {
                throw new Exception("mixerSetControlDetails" + mmresult.ToString());
            }
        }
        public static void Mute(bool mute)
        {
            // Check if this is vista or XP
            if (System.Environment.OSVersion.Version.Major >= 6)
            {
                EndpointVolume epVol = new EndpointVolume();
                epVol.Mute = mute;
                epVol.Dispose();
            }
            else
            {
                int mixerID = 0;

                if (mixerOpen(out mixerID, 0, 0, 0, 0) == MMSYSERR_NOERROR)
                {
                    MIXERLINE line = new MIXERLINE();
                    line.cbStruct        = Marshal.SizeOf(line);
                    line.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;

                    if (mixerGetLineInfoA(mixerID, ref line, MIXER_GETLINEINFOF_COMPONENTTYPE) == MMSYSERR_NOERROR)
                    {
                        int          sizeofMIXERCONTROL = 152;
                        MIXERCONTROL mixerControl       = new MIXERCONTROL();

                        MIXERLINECONTROLS lineControl = new MIXERLINECONTROLS();

                        lineControl.pamxctrl  = Marshal.AllocCoTaskMem(sizeofMIXERCONTROL);
                        lineControl.cbStruct  = Marshal.SizeOf(lineControl);
                        lineControl.dwLineID  = line.dwLineID;
                        lineControl.dwControl = MIXERCONTROL_CONTROLTYPE_MUTE;
                        lineControl.cControls = 1;
                        lineControl.cbmxctrl  = sizeofMIXERCONTROL;

                        mixerControl.cbStruct = sizeofMIXERCONTROL;

                        if (mixerGetLineControlsA(mixerID, ref lineControl, MIXER_GETLINECONTROLSF_ONEBYTYPE) == MMSYSERR_NOERROR)
                        {
                            mixerControl = (MIXERCONTROL)Marshal.PtrToStructure(lineControl.pamxctrl, typeof(MIXERCONTROL));

                            MIXERCONTROLDETAILS         controlDetails = new MIXERCONTROLDETAILS();
                            MIXERCONTROLDETAILS_BOOLEAN muteValue      = new MIXERCONTROLDETAILS_BOOLEAN();

                            controlDetails.item        = 0;
                            controlDetails.dwControlID = mixerControl.dwControlID;
                            controlDetails.cbStruct    = Marshal.SizeOf(controlDetails);
                            controlDetails.cbDetails   = Marshal.SizeOf(muteValue);
                            controlDetails.cChannels   = 1;

                            muteValue.dwValue = Convert.ToInt32(mute);

                            controlDetails.paDetails = Marshal.AllocCoTaskMem(Marshal.SizeOf(muteValue));

                            Marshal.StructureToPtr(muteValue, controlDetails.paDetails, false);

                            int rc = mixerSetControlDetails(mixerID, ref controlDetails, MIXER_SETCONTROLDETAILSF_VALUE);

                            Marshal.FreeCoTaskMem(controlDetails.paDetails);
                            Marshal.FreeCoTaskMem(lineControl.pamxctrl);
                        }
                    }
                }
            }
        }
Beispiel #5
0
        public static void Mute(bool mute)
        {
            // Check if this is vista or XP
            if (System.Environment.OSVersion.Version.Major >= 6)
            {
                EndpointVolume epVol = new EndpointVolume();
                epVol.Mute = mute;
                epVol.Dispose();
            }
            else
            {
                int mixerID = 0;

                if (mixerOpen(out mixerID, 0, 0, 0, 0) == MMSYSERR_NOERROR)
                {
                    MIXERLINE line = new MIXERLINE();
                    line.cbStruct = Marshal.SizeOf(line);
                    line.dwComponentType = MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;

                    if (mixerGetLineInfoA(mixerID, ref line, MIXER_GETLINEINFOF_COMPONENTTYPE) == MMSYSERR_NOERROR)
                    {
                        int sizeofMIXERCONTROL = 152;
                        MIXERCONTROL mixerControl = new MIXERCONTROL();

                        MIXERLINECONTROLS lineControl = new MIXERLINECONTROLS();

                        lineControl.pamxctrl = Marshal.AllocCoTaskMem(sizeofMIXERCONTROL);
                        lineControl.cbStruct = Marshal.SizeOf(lineControl);
                        lineControl.dwLineID = line.dwLineID;
                        lineControl.dwControl = MIXERCONTROL_CONTROLTYPE_MUTE;
                        lineControl.cControls = 1;
                        lineControl.cbmxctrl = sizeofMIXERCONTROL;

                        mixerControl.cbStruct = sizeofMIXERCONTROL;

                        if (mixerGetLineControlsA(mixerID, ref lineControl, MIXER_GETLINECONTROLSF_ONEBYTYPE) == MMSYSERR_NOERROR)
                        {
                            mixerControl = (MIXERCONTROL)Marshal.PtrToStructure(lineControl.pamxctrl, typeof(MIXERCONTROL));

                            MIXERCONTROLDETAILS controlDetails = new MIXERCONTROLDETAILS();
                            MIXERCONTROLDETAILS_BOOLEAN muteValue = new MIXERCONTROLDETAILS_BOOLEAN();

                            controlDetails.item = 0;
                            controlDetails.dwControlID = mixerControl.dwControlID;
                            controlDetails.cbStruct = Marshal.SizeOf(controlDetails);
                            controlDetails.cbDetails = Marshal.SizeOf(muteValue);
                            controlDetails.cChannels = 1;

                            muteValue.dwValue = Convert.ToInt32(mute);

                            controlDetails.paDetails = Marshal.AllocCoTaskMem(Marshal.SizeOf(muteValue));

                            Marshal.StructureToPtr(muteValue, controlDetails.paDetails, false);

                            int rc = mixerSetControlDetails(mixerID, ref controlDetails, MIXER_SETCONTROLDETAILSF_VALUE);

                            Marshal.FreeCoTaskMem(controlDetails.paDetails);
                            Marshal.FreeCoTaskMem(lineControl.pamxctrl);
                        }
                    }
                }
            }
        }
Beispiel #6
0
        protected static bool GetMuteControl(int hmixer, int componentType, int ctrlType, out MIXERCONTROL mxc, out bool vCurrentMute)
        {
            // This function attempts to obtain a mixer control.
            // Returns True if successful.
            MIXERLINECONTROLS           mxlc  = new MIXERLINECONTROLS();
            MIXERLINE                   mxl   = new MIXERLINE();
            MIXERCONTROLDETAILS         pmxcd = new MIXERCONTROLDETAILS();
            MIXERCONTROLDETAILS_BOOLEAN du    = new MIXERCONTROLDETAILS_BOOLEAN();

            mxc = new MIXERCONTROL();
            int  rc;
            bool retValue;

            vCurrentMute = false;

            mxl.cbStruct        = Marshal.SizeOf(mxl);
            mxl.dwComponentType = componentType;

            rc = mixerGetLineInfoA(hmixer, ref mxl, MIXER_GETLINEINFOF_COMPONENTTYPE);

            if (MMSYSERR_NOERROR == rc)
            {
                int sizeofMIXERCONTROL = 152;
                int ctrl = Marshal.SizeOf(typeof(MIXERCONTROL));
                mxlc.pamxctrl  = Marshal.AllocCoTaskMem(sizeofMIXERCONTROL);
                mxlc.cbStruct  = Marshal.SizeOf(mxlc);
                mxlc.dwLineID  = mxl.dwLineID;
                mxlc.dwControl = ctrlType;
                mxlc.cControls = 1;
                mxlc.cbmxctrl  = sizeofMIXERCONTROL;

                // Allocate a buffer for the control
                mxc.cbStruct = sizeofMIXERCONTROL;

                // Get the control
                rc = mixerGetLineControlsA(hmixer, ref mxlc, MIXER_GETLINECONTROLSF_ONEBYTYPE);
                if (MMSYSERR_NOERROR == rc)
                {
                    retValue = true;

                    // Copy the control into the destination structure
                    mxc = (MIXERCONTROL)Marshal.PtrToStructure(
                        mxlc.pamxctrl, typeof(MIXERCONTROL));
                }
                else
                {
                    retValue = false;
                }

                int sizeofMIXERCONTROLDETAILS         = Marshal.SizeOf(typeof(MIXERCONTROLDETAILS));
                int sizeofMIXERCONTROLDETAILS_BOOLEAN = Marshal.SizeOf(typeof(MIXERCONTROLDETAILS_BOOLEAN));
                pmxcd.cbStruct    = sizeofMIXERCONTROLDETAILS;
                pmxcd.dwControlID = mxc.dwControlID;
                pmxcd.paDetails   = Marshal.AllocCoTaskMem(sizeofMIXERCONTROLDETAILS_BOOLEAN);
                pmxcd.cChannels   = 1;
                pmxcd.item        = 0;
                pmxcd.cbDetails   = sizeofMIXERCONTROLDETAILS_BOOLEAN;

                rc = mixerGetControlDetailsA(hmixer, ref pmxcd, MIXER_GETCONTROLDETAILSF_VALUE);

                du = (MIXERCONTROLDETAILS_BOOLEAN)Marshal.PtrToStructure(pmxcd.paDetails, typeof(MIXERCONTROLDETAILS_BOOLEAN));

                vCurrentMute = (du.fValue != 0);

                return(retValue);
            }

            retValue = false;
            return(retValue);
        }