Exemplo n.º 1
0
 public int SetDefaultDevice(string deviceID)
 {
     _policyConfigClient.SetDefaultEndpoint(deviceID, ERole.eConsole);
     _policyConfigClient.SetDefaultEndpoint(deviceID, ERole.eMultimedia);
     _policyConfigClient.SetDefaultEndpoint(deviceID, ERole.eCommunications);
     return(0);
 }
Exemplo n.º 2
0
        public static void SetDefaultEndpoint(string devId, ERole eRole)
        {
            object o = (object)null;

            try
            {
                o = GetPolicyConfig();
                IPolicyConfigX     policyConfigX     = o as IPolicyConfigX;
                IPolicyConfig      policyConfig      = o as IPolicyConfig;
                IPolicyConfigVista policyConfigVista = o as IPolicyConfigVista;
                if (policyConfig != null)
                {
                    policyConfig.SetDefaultEndpoint(devId, eRole);
                }
                else if (policyConfigVista != null)
                {
                    policyConfigVista.SetDefaultEndpoint(devId, eRole);
                }
                else
                {
                    policyConfigX?.SetDefaultEndpoint(devId, eRole);
                }
            }
            finally
            {
                if (o != null && Marshal.IsComObject(o))
                {
                    Marshal.FinalReleaseComObject(o);
                }
                GC.Collect();
            }
        }
Exemplo n.º 3
0
 public void SetDefaultEndpoint(string deviceId, ERole role)
 {
     try
     {
         policyConfig.SetDefaultEndpoint(deviceId, role);
     }
     catch { }
 }
 public void SetDefaultDevice(EDataFlow dataFlow, ERole role, string devId)
 {
     try
     {
         _policyConfig.SetDefaultEndpoint(devId, role);
     }
     catch (Exception)
     {
     }
 }
Exemplo n.º 5
0
        // Switches default device to current default devices. Doesn't change the device, but sends an event so the program needs to aquire the device again, this time using our hook.
        public static void switchDefaultDevice()
        {
            List <SoundInfoDevice> devices = getSoundInfo();

            if (devices.Count >= 2)
            {
                IMMDeviceEnumerator enumerator = (IMMDeviceEnumerator) new DeviceEnumerator();
                string id = enumerator.GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eMultimedia).GetId();

                IPolicyConfig policyConfig = (IPolicyConfig) new IPolicyConfigClass();
                policyConfig.SetDefaultEndpoint(id, ERole.eMultimedia);
            }
        }
Exemplo n.º 6
0
        public void SetDefaultEndpoint(string devID, CSCore.CoreAudioAPI.Role eRole)
        {
            if (_PolicyConfig != null)
            {
                Marshal.ThrowExceptionForHR(_PolicyConfig.SetDefaultEndpoint(devID, eRole));
                return;
            }

            if (_PolicyConfig10 != null)
            {
                Marshal.ThrowExceptionForHR(_PolicyConfig10.SetDefaultEndpoint(devID, eRole));
            }
        }
Exemplo n.º 7
0
 public void SetDefaultEndpoint(string devID, DeviceRoles eRole)
 {
     if (_PolicyConfig != null)
     {
         Marshal.ThrowExceptionForHR(_PolicyConfig.SetDefaultEndpoint(devID, eRole));
         return;
     }
     if (_PolicyConfigVista != null)
     {
         Marshal.ThrowExceptionForHR(_PolicyConfigVista.SetDefaultEndpoint(devID, eRole));
         return;
     }
     if (_PolicyConfig10 != null)
     {
         Marshal.ThrowExceptionForHR(_PolicyConfig10.SetDefaultEndpoint(devID, eRole));
     }
 }
Exemplo n.º 8
0
 public void SetDefaultEndpoint(string deviceId, NAudio.CoreAudioApi.Role role)
 {
     if (_PolicyConfig != null)
     {
         Marshal.ThrowExceptionForHR(_PolicyConfig.SetDefaultEndpoint(deviceId, role));
         return;
     }
     if (_PolicyConfigVista != null)
     {
         Marshal.ThrowExceptionForHR(_PolicyConfigVista.SetDefaultEndpoint(deviceId, role));
         return;
     }
     if (_PolicyConfig10 != null)
     {
         Marshal.ThrowExceptionForHR(_PolicyConfig10.SetDefaultEndpoint(deviceId, role));
     }
 }
Exemplo n.º 9
0
        public void SetDefaultAudioDevice(AudioDevice device, AudioDeviceRole role)
        {
            if (device == null)
            {
                throw new ArgumentNullException("device");
            }

            // BADNESS: The following code uses an undocumented interface provided by the Audio SDK. This is completely
            // unsupported, and should be used for amusement purposes only. This is *extremely likely* to be broken
            // in future updates and/or versions of Windows. If Larry Osterman was dead, he would be rolling over
            // in his grave if he knew you were using this for nefarious purposes.
            IPolicyConfig config = (IPolicyConfig) new PolicyConfig();
            int           hr     = config.SetDefaultEndpoint(device.Id, role);

            if (hr != HResult.OK)
            {
                throw Marshal.GetExceptionForHR(hr);
            }
        }
Exemplo n.º 10
0
 public void SetDefaultEndpoint(string devID, ERole eRole)
 {
     Marshal.ThrowExceptionForHR(_PolicyConfig.SetDefaultEndpoint(devID, eRole));
 }
Exemplo n.º 11
0
 public int SetDefaultDevice(string deviceID, ERole role)
 {
     _policyConfigClient.SetDefaultEndpoint(deviceID, role);
     return(0);
 }
Exemplo n.º 12
0
 public void SetDefaultEndpoint(string id, Role role)
 {
     Marshal.ThrowExceptionForHR(_policyConfig.SetDefaultEndpoint(id, role));
 }