private void SwitchDevice()
        {
            var manager = new AudioDeviceManager();
            var devices = manager.GetAudioDevices(AudioDeviceKind.Playback, AudioDeviceState.Active);
            var current = manager.GetDefaultAudioDevice(AudioDeviceKind.Playback, AudioDeviceRole.Multimedia)
                          .ToString()
                          .ToUpper()
                          .Replace(" ", "");

            var headphones = Args["headphones"]
                             .ToUpper()
                             .Replace(" ", "");

            var speakers = Args["speakers"]
                           .ToUpper()
                           .Replace(" ", "");

            AudioDevice device = null;

            if (current == headphones)
            {
                device = devices.FirstOrDefault(d => d.ToString().ToUpper().Replace(" ", "") == speakers);
            }
            else
            {
                device = devices.FirstOrDefault(d => d.ToString().ToUpper().Replace(" ", "") == headphones);
            }

            if (device != null)
            {
                manager.SetDefaultAudioDevice(device, AudioDeviceRole.Multimedia);
            }
        }
Exemplo n.º 2
0
        public AudioDeviceViewModelManager(AudioDeviceManager deviceManager)
        {
            _deviceManager = deviceManager;

            RegisterHandlers();
            AddAll();
        }
        private static void OnContextMenuOpening(AudioDeviceManager manager, AudioContextMenu strip)
        {
            AddDeviceCommands(manager, strip, AudioDeviceKind.Playback, Settings.Default.ShowPlaybackDevices, Resources.NoPlaybackDevices);
            AddDeviceCommands(manager, strip, AudioDeviceKind.Recording, Settings.Default.ShowRecordingDevices, Resources.NoRecordingDevices);

            if (strip.Items.Count == 0)
            {
                strip.AddCommand(new DisabledCommand(Resources.NoDevices));
            }
        }
Exemplo n.º 4
0
        public NotificationIconPresenter(
            IApplication application,
            PresenterHost presenterManager,
            AudioDeviceManager deviceManager)
        {
            _application      = application;
            _presenterManager = presenterManager;

            _deviceManager = deviceManager;
            _deviceManager.DefaultDeviceChanged += OnDefaultDeviceChanged;
        }
        public static AudioContextMenu CreateContextMenu(AudioDeviceManager manager)
        {
            AudioContextMenu strip = new AudioContextMenu();

            strip.IsDynamic = true;                            // We dynamically add the devices when the menu is opened
            strip.AutoCloseWhenItemWithDropDownClicked = true; // When something clicks the "Device" we autoclose
            strip.ShowCheckMargin = true;
            strip.ShowImageMargin = true;
            strip.Opening        += (sender, e) => OnContextMenuOpening(manager, strip);

            return(strip);
        }
        private static void AddCommand(AudioDeviceManager manager, ContextMenuStrip strip, AudioDeviceCollection devices, AudioDeviceState state)
        {
            foreach (AudioDevice device in devices.Where(d => d.State == state))
            {
                ToolStripDropDown dropDown = strip.AddNestedCommand(new AudioDeviceCommand(manager, device));

                if (device.State == AudioDeviceState.Active)
                {
                    dropDown.AddCommand(new SetAsDefaultMultimediaDeviceCommand(manager, device));
                    dropDown.AddCommand(new SetAsDefaultCommunicationDeviceCommand(manager, device));
                }
            }
        }
Exemplo n.º 7
0
        public Main()
        {
            InitializeComponent();

            AudioDeviceManager.RefreshDevices();
            PropertyPanelManager.SetPropertyPanel(propertyPanel);
            PanelManager.CorePanel     = corePanel;
            PanelManager.MainPanel     = mainPanel;
            PanelManager.ButtonPanel   = buttonPanel;
            PanelManager.PropertyPanel = propertyPanel;
            PanelManager.SidePanel     = sidePanel;
            PanelManager.TreeView      = treeView;

            DoubleBuffered = true;
        }
        private AudioDeviceDefaultState CalculateDeviceDefaultState(AudioDeviceManager deviceManager)
        {
            AudioDeviceDefaultState state = AudioDeviceDefaultState.None;

            if (deviceManager.IsDefaultAudioDevice(_device, AudioDeviceRole.Multimedia))
            {
                state |= AudioDeviceDefaultState.Multimedia;
            }

            if (deviceManager.IsDefaultAudioDevice(_device, AudioDeviceRole.Communications))
            {
                state |= AudioDeviceDefaultState.Communications;
            }

            return(state);
        }
        private static void AddDeviceCommands(AudioDeviceManager manager, ContextMenuStrip strip, AudioDeviceKind kind, bool condition, string noDeviceText)
        {
            if (condition)
            {
                strip.AddSeparatorIfNeeded();

                AudioDeviceCollection devices = GetDevices(manager, kind);
                if (devices.Count == 0)
                {
                    strip.AddCommand(new DisabledCommand(noDeviceText));
                }
                else
                {
                    AddCommand(manager, strip, devices, AudioDeviceState.Active);
                    AddCommand(manager, strip, devices, AudioDeviceState.Unplugged);
                    AddCommand(manager, strip, devices, AudioDeviceState.Disabled);
                    AddCommand(manager, strip, devices, AudioDeviceState.NotPresent);
                }
            }
        }
        public void UpdateStatus(AudioDeviceManager deviceManager)
        {
            DefaultState = CalculateDeviceDefaultState(deviceManager);
            Kind         = _device.Kind;
            State        = _device.State;
            IsVisible    = CalculateIsVisible();

            // Only do work such as get text, icons, etc if we're visible
            if (IsVisible)
            {
                Description             = TryGetOrDefault(_device.TryGetDeviceDescription, Description);
                FriendlyName            = TryGetOrDefault(_device.TryDeviceFriendlyName, FriendlyName);
                DeviceStateFriendlyName = GetDeviceStateFriendlyName();

                if (_device.TryGetDeviceClassIconPath(out string iconPath))
                {
                    Image = GetImage(iconPath);
                }
            }
        }
        private static AudioDeviceCollection GetDevices(AudioDeviceManager manager, AudioDeviceKind kind)
        {
            AudioDeviceState state = AudioDeviceState.Active;

            if (Settings.Default.ShowDisabledDevices)
            {
                state |= AudioDeviceState.Disabled;
            }

            if (Settings.Default.ShowUnpluggedDevices)
            {
                state |= AudioDeviceState.Unplugged;
            }

            if (Settings.Default.ShowNotPresentDevices)
            {
                state |= AudioDeviceState.NotPresent;
            }

            return(manager.GetAudioDevices(kind, state));
        }
Exemplo n.º 12
0
 protected SetAsDefaultDeviceCommandBase(AudioDeviceManager manager, AudioDeviceRole role)
 {
     _manager = manager;
     _role    = role;
 }
Exemplo n.º 13
0
 public NotificationIconService(AudioDeviceManager manager, IApplication application)
 {
     _manager     = manager;
     _application = application;
 }
 protected SetAsDefaultDeviceCommand(AudioDeviceManager manager, AudioDevice device, AudioDeviceRole role)
 {
     _manager = manager;
     _device  = device;
     _role    = role;
 }
 public SetAsDefaultMultimediaDeviceCommand(AudioDeviceManager manager)
     : base(manager, AudioDeviceRole.Multimedia)
 {
     Text  = Resources.SetAsDefaultMultimediaDevice;
     Image = Resources.DefaultMultimediaDevice;
 }
Exemplo n.º 16
0
 public AudioDeviceCommand(AudioDeviceManager deviceManager, AudioDevice device)
 {
     _deviceManager = deviceManager;
     _device        = device;
 }
 public SetAsDefaultMultimediaDeviceCommand(AudioDeviceManager manager, AudioDevice device)
     : base(manager, device, AudioDeviceRole.Console)
 {
     Text  = Resources.SetAsDefaultMultimediaDevice;
     Image = Resources.DefaultMultimediaDevice.ToBitmap();
 }
Exemplo n.º 18
0
 public InputSwitcherService(AudioDeviceManager manager)
 {
     _manager = manager;
 }
 public void InitializeAudioDevice()
 {
     audioDeviceSwitcher = new AudioDeviceManager();
 }
Exemplo n.º 20
0
 public AudioDeviceCommand(AudioDeviceManager deviceManager)
 {
     _deviceManager = deviceManager;
 }
 public SetAsDefaultCommunicationDeviceCommand(AudioDeviceManager manager)
     : base(manager, AudioDeviceRole.Communications)
 {
     Text  = Resources.SetAsDefaultComunicationDevice;
     Image = Resources.DefaultCommunicationsDevice;
 }
Exemplo n.º 22
0
        //public static NotificationSoundManager(FileManager fm, AudioDeviceManager adm)
        //{
        //    this.fm = fm;
        //    this.adm = adm;
        //    LoadSettings();
        //}

        public static void LoadSettings()
        {
            outputDeviceID      = AudioDeviceManager.GetNotificationOutputDeviceID();
            _notificationVolume = FileManager.GetNotificationVolume();
        }