public AudioDeviceCollection GetAudioDevices(AudioDeviceKind kind, AudioDeviceState state) { IMMDeviceCollection result; Marshal.ThrowExceptionForHR(_underlyingEnumerator.EnumAudioEndpoints(kind, state, out result)); return(new AudioDeviceCollection(result)); }
public AudioDeviceCollection GetAudioDevices(AudioDeviceKind kind, AudioDeviceState state) { IMMDeviceCollection underlyingCollection; int hr = _deviceEnumerator.EnumAudioEndpoints(kind, state, out underlyingCollection); if (hr == HResult.OK) return new AudioDeviceCollection(underlyingCollection); throw Marshal.GetExceptionForHR(hr); }
void IMMNotificationClient.OnDefaultDeviceChanged(AudioDeviceKind kind, AudioDeviceRole role, string deviceId) { var handler = DefaultDeviceChanged; if (handler != null) { AudioDevice device = GetDevice(deviceId); handler(this, new DefaultAudioDeviceEventArgs(device, kind, role)); } }
public AudioDeviceCollection GetAudioDevices(AudioDeviceKind kind, AudioDeviceState state) { int hr = _deviceEnumerator.EnumAudioEndpoints(kind, state, out IMMDeviceCollection underlyingCollection); if (hr == HResult.OK) { return(new AudioDeviceCollection(underlyingCollection)); } throw Marshal.GetExceptionForHR(hr); }
private void AddDeviceCommands(AudioDeviceKind kind, string noDeviceCommandId, bool firstRun = false) { AudioDeviceViewModel[] devices = GetDevices(kind); foreach (AudioDeviceViewModel device in devices) { ToolStripMenuItem item = ContextMenu.BindCommand(_commandManager, CommandId.SetAsDefaultDevice, device); item.DropDownDirection = ToolStripDropDownDirection.AboveRight; item.MouseUp += OnItemMouseUp; } ContextMenu.BindCommand(_commandManager, noDeviceCommandId); }
public AudioDevice GetDefaultAudioDevice(AudioDeviceKind kind, AudioDeviceRole role) { int hr = _deviceEnumerator.GetDefaultAudioEndpoint(kind, role, out IMMDevice underlyingDevice); if (hr == HResult.OK) { return(new AudioDevice(underlyingDevice)); } if (hr == HResult.NotFound || hr == HResult.FileNotFound) // See #33 { return(null); } throw Marshal.GetExceptionForHR(hr); }
void IMMNotificationClient.OnDefaultDeviceChanged(AudioDeviceKind kind, AudioDeviceRole role, string deviceId) { InvokeOnSynchronizationContext(() => { var handler = DefaultDeviceChanged; if (handler != null) { AudioDevice device = null; if (deviceId != null) { device = GetDevice(deviceId); } handler(this, new DefaultAudioDeviceEventArgs(device, kind, role)); } }); }
public static IAudioDeviceManager CreateAudioDeviceManager(AudioDeviceKind kind) { if (kind == AudioDeviceKind.Playback) { if (s_playbackDevices == null) { s_playbackDevices = new AudioDeviceManager(AudioDeviceKind.Playback); } return(s_playbackDevices); } else { if (s_recordingDevices == null) { s_recordingDevices = new AudioDeviceManager(AudioDeviceKind.Recording); } return(s_recordingDevices); } }
public AudioDeviceManager(AudioDeviceKind kind) { _kind = kind; _dispatcher = Dispatcher.CurrentDispatcher; _devices = new AudioDeviceCollection(); _policyConfigService = new AudioPolicyConfigService(Flow); TraceLine($"Create"); Task.Factory.StartNew(() => { try { _enumerator = (IMMDeviceEnumerator) new MMDeviceEnumerator(); _enumerator.RegisterEndpointNotificationCallback(this); var devices = _enumerator.EnumAudioEndpoints(Flow, DeviceState.ACTIVE); uint deviceCount = devices.GetCount(); for (uint i = 0; i < deviceCount; i++) { ((IMMNotificationClient)this).OnDeviceAdded(devices.Item(i).GetId()); } _dispatcher.Invoke((Action)(() => { QueryDefaultDevice(); Loaded?.Invoke(this, null); })); } catch (Exception ex) { // Even through we're going to be broken, show the tray icon so the user can collect debug data. AppTrace.LogWarning(ex); _dispatcher.Invoke((Action)(() => { Loaded?.Invoke(this, null); })); } }); TraceLine($"Create Exit"); }
public AudioDevice GetDefaultAudioDevice(AudioDeviceKind kind, AudioDeviceRole role) { const int E_NOTFOUND = unchecked ((int)0x80070490); IMMDevice underlyingDevice; int hr = _underlyingEnumerator.GetDefaultAudioEndpoint(kind, role, out underlyingDevice); if (hr == HResult.OK) { return(new AudioDevice(underlyingDevice)); } if (hr == E_NOTFOUND) { return(null); } throw Marshal.GetExceptionForHR(hr); }
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)); }
public DefaultAudioDeviceEventArgs(AudioDevice device, AudioDeviceKind kind, AudioDeviceRole role) : base(device) { _kind = kind; _role = role; }
public NoDevicesCommandBase(string text, AudioDeviceViewModelManager viewModelManager, AudioDeviceKind kind) : base(text) { _kind = kind; _viewModelManager = viewModelManager; }
void IMMNotificationClient.OnDefaultDeviceChanged(AudioDeviceKind kind, AudioDeviceRole role, string deviceId) { InvokeOnSynchronizationContext(() => { var handler = DefaultDeviceChanged; if (handler != null) { AudioDevice device = null; if (deviceId != null) device = GetDevice(deviceId); handler(this, new DefaultAudioDeviceEventArgs(device, kind, role)); } }); }
public AudioDevice GetDefaultAudioDevice(AudioDeviceKind kind, AudioDeviceRole role) { IMMDevice underlyingDevice; int hr = _deviceEnumerator.GetDefaultAudioEndpoint(kind, role, out underlyingDevice); if (hr == HResult.OK) return new AudioDevice(underlyingDevice); if (hr == HResult.NotFound || hr == HResult.FileNotFound) // See #33 return null; throw Marshal.GetExceptionForHR(hr); }
public static IAudioDeviceManager CreateNonSharedDeviceManager(AudioDeviceKind kind) { return(new AudioDeviceManager(kind)); }
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); } } }
private AudioDeviceViewModel[] GetDevices(AudioDeviceKind kind) { return(_viewModelManager.ViewModels.Where(v => v.Device.Kind == kind) .ToArray()); }
private AudioDeviceViewModel[] GetDevices(AudioDeviceKind kind) { return _viewModelManager.ViewModels.Where(v => v.Device.Kind == kind) .ToArray(); }