Ejemplo n.º 1
0
        public void AddDevice(Device device)
        {
            if (device.DeviceName.Contains("none"))
            {
                return;
            }
            devices.Add(device);
            switch (device.DeviceType)
            {
            case DeviceTypeEnum.AUDIO_INPUT:
            case DeviceTypeEnum.AUDIO_OUTPUT:
            {
                var audioInput   = GetDevicesByType(DeviceTypeEnum.AUDIO_INPUT).FirstOrDefault();
                var audioOutput  = GetDevicesByType(DeviceTypeEnum.AUDIO_OUTPUT).FirstOrDefault();
                var inputHandle  = audioInput?.DeviceHandle;
                var outputHandle = audioOutput?.DeviceHandle;
                if (null == CurrentAudioInputDevice && null != audioInput)
                {
                    CurrentAudioInputDevice = audioInput;
                    WrapperProxy.SetAudioDevice(inputHandle, outputHandle);
                    WrapperProxy.SetAudioDeviceForRingtone(outputHandle);
                }
                if (null == CurrentAudioOutputDevice && null != outputHandle)
                {
                    CurrentAudioOutputDevice = audioOutput;
                    WrapperProxy.SetAudioDevice(inputHandle, outputHandle);
                    WrapperProxy.SetAudioDeviceForRingtone(outputHandle);
                }
            }
            break;

            case DeviceTypeEnum.VIDEO_INPUT:
            {
                if (null == CurrentAudioOutputDevice)
                {
                    var video       = GetDevicesByType(DeviceTypeEnum.VIDEO_INPUT).FirstOrDefault();
                    var videoHandle = video?.DeviceHandle;
                    if (null != videoHandle)
                    {
                        CurrentVideoInputDevice = video;
                        WrapperProxy.SetVideoDevice(videoHandle);
                    }
                }
            } break;
            }
        }
Ejemplo n.º 2
0
        public bool RemoveDevice(string deviceHandle)
        {
            for (int i = 0; i < devices.Count(); i++)
            {
                var device = devices[i];
                if (deviceHandle == device.DeviceHandle)
                {
                    devices.Remove(device);
                    switch (device.DeviceType)
                    {
                    case DeviceTypeEnum.AUDIO_INPUT:
                    {
                        if (CurrentAudioInputDevice == device)
                        {
                            var audioInput   = GetDevicesByType(DeviceTypeEnum.AUDIO_INPUT).FirstOrDefault();
                            var audioOutput  = GetDevicesByType(DeviceTypeEnum.AUDIO_OUTPUT).FirstOrDefault();
                            var inputHandle  = audioInput?.DeviceHandle;
                            var outputHandle = audioOutput?.DeviceHandle;
                            if (null == CurrentAudioInputDevice && null != audioInput)
                            {
                                CurrentAudioInputDevice = audioInput;
                                WrapperProxy.SetAudioDevice(inputHandle, outputHandle);
                                WrapperProxy.SetAudioDeviceForRingtone(outputHandle);
                            }
                            if (null == CurrentAudioOutputDevice && null != outputHandle)
                            {
                                CurrentAudioOutputDevice = audioOutput;
                                WrapperProxy.SetAudioDevice(inputHandle, outputHandle);
                                WrapperProxy.SetAudioDeviceForRingtone(outputHandle);
                            }
                        }
                    } break;

                    case DeviceTypeEnum.AUDIO_OUTPUT:
                    {
                        if (CurrentAudioOutputDevice == device)
                        {
                            var audioInput   = GetDevicesByType(DeviceTypeEnum.AUDIO_INPUT).FirstOrDefault();
                            var audioOutput  = GetDevicesByType(DeviceTypeEnum.AUDIO_OUTPUT).FirstOrDefault();
                            var inputHandle  = audioInput?.DeviceHandle;
                            var outputHandle = audioOutput?.DeviceHandle;
                            if (null == CurrentAudioInputDevice && null != audioInput)
                            {
                                CurrentAudioInputDevice = audioInput;
                                WrapperProxy.SetAudioDevice(inputHandle, outputHandle);
                                WrapperProxy.SetAudioDeviceForRingtone(outputHandle);
                            }
                            if (null == CurrentAudioOutputDevice && null != outputHandle)
                            {
                                CurrentAudioOutputDevice = audioOutput;
                                WrapperProxy.SetAudioDevice(inputHandle, outputHandle);
                                WrapperProxy.SetAudioDeviceForRingtone(outputHandle);
                            }
                        }
                    }
                    break;

                    case DeviceTypeEnum.VIDEO_INPUT:
                    {
                        if (CurrentVideoInputDevice == device)
                        {
                            var video       = GetDevicesByType(DeviceTypeEnum.VIDEO_INPUT).FirstOrDefault();
                            var videoHandle = video?.DeviceHandle;
                            WrapperProxy.SetVideoDevice(videoHandle);
                        }
                    }
                    break;
                    }
                    return(true);
                }
            }
            return(false);
        }