public void TestAudioDevicesOperator(AudioDeviceType deviceType) { var devices1 = AudioDevice.GetAudioDevices(AudioDataFlow.Render, deviceType); var devices2 = AudioDevice.GetAudioDevices(AudioDataFlow.Render, deviceType); for (int i = 0; i < devices1.Length; i++) { Assert.False(Object.ReferenceEquals(devices1[i], devices2[i])); Assert.True(devices1[i] == devices2[i]); Assert.False(devices1[i] != devices2[i]); Assert.True(devices1[i].GetHashCode() == devices2[i].GetHashCode()); Assert.False(devices1[i] == null); Assert.False(null == devices1[i]); Assert.True(devices1[i] != null); Assert.True(null != devices1[i]); if (i >= 1) { Assert.False(devices1[i] == devices2[i - 1]); Assert.True(devices1[i] != devices2[i - 1]); Assert.False(devices1[i].GetHashCode() == devices2[i - 1].GetHashCode()); } } }
public void TestAudioDevices(AudioDeviceType deviceType) { var devices = AudioDevice.GetAudioDevices(AudioDataFlow.Render, deviceType); Assert.NotNull(devices); foreach (var item in devices) { Assert.NotNull(item.Id); Assert.NotNull(item.Guid.ToString()); Assert.Equal(deviceType, item.DeviceType); Assert.Equal(AudioDataFlow.Render, item.DataFlow); Assert.NotNull(item.Name); Assert.NotNull(item.FriendlyName); output.WriteLine("Id: {0}", item.Id); output.WriteLine("Guid: {0}", item.Guid); output.WriteLine("Number: {0}", item.Number); output.WriteLine("DeviceType: {0}", item.DeviceType); output.WriteLine("DataFlow: {0}", item.DataFlow); output.WriteLine("Name: {0}", item.Name); output.WriteLine("FriendlyName: {0}", item.FriendlyName); output.WriteLine("MMDevice: {0}", (item.MMDevice != null)); output.WriteLine("----"); } }
public AudioDevice(AudioDeviceType _audioDeviceType, int _index, string _name, int _channels) { name = _name; index = _index; audioDeviceType = _audioDeviceType; channels = _channels; }
/// <summary> /// Cycle the audio device for the given type /// </summary> /// <param name="type"></param> public override bool CycleAudioDevice(AudioDeviceType type) { ICollection <IAudioDevice> audioDevices; switch (type) { case AudioDeviceType.Playback: audioDevices = AppModel.Instance.AvailablePlaybackDevices; break; case AudioDeviceType.Recording: audioDevices = AppModel.Instance.AvailableRecordingDevices; break; default: throw new ArgumentOutOfRangeException(nameof(type), type, null); } switch (audioDevices.Count) { case 0: throw new AppModel.NoDevicesException(); case 1: return(false); } return(SetActiveDevice(GetNextDevice(audioDevices, type))); }
public PlayerConfiguration() { CacheBeforePlaying = true; // temporarily make this the default - remove this feature altogether of url streaming proves to be working via the FilePlayer WasapiExclusiveMode = false; // exclusive mode simply does not work reliably ... WasapiLatency = 20; EnabledAudioTypes = new AudioDeviceType[] { AudioDeviceType.Wasapi }; }
public void SetSelectedAudioDevices(AudioDeviceType audioDeviceType) { try { switch (audioDeviceType) { case AudioDeviceType.Capture: using (AudioCaptureDeviceDialog audioCaptureDeviceDialog = new AudioCaptureDeviceDialog(SelectedCaptureDevicesCollection)) { if (audioCaptureDeviceDialog.ShowDialog().Value) { SelectedCaptureDevicesCollection = new ObservableCollection <AudioCaptureDevice>(audioCaptureDeviceDialog.SelectedAudioCaptureDevices); } } break; case AudioDeviceType.Render: using (AudioOutputDeviceDialog audioOutputDeviceDialog = new AudioOutputDeviceDialog(SelectedOutputDevicesCollection)) { if (audioOutputDeviceDialog.ShowDialog().Value) { SelectedOutputDevicesCollection = new ObservableCollection <AudioOutputDevice>(audioOutputDeviceDialog.SelectedAudioOutputDevices); } } break; } } catch (Exception ex) { ApplicationLogger.Log(ex.Message, ex.StackTrace); } }
/// <summary> /// Gets Audio devices. /// </summary> /// <param name="dataFlow">Audio data flow. In current version, only <see cref="AudioDataFlow.Render"/> is supported.</param> /// <param name="deviceType">Audio device type.</param> /// <param name="deviceRole">Audio device role.</param> /// <returns>Audio device list.</returns> public static AudioDevice[] GetAudioDevices(AudioDataFlow dataFlow, AudioDeviceType deviceType = AudioDeviceType.WASAPI, AudioDeviceRole deviceRole = AudioDeviceRole.Multimedia) { AudioDevice[] result; if (deviceType == AudioDeviceType.WASAPI) { result = GetWASAPIAudioDevices(dataFlow, deviceRole); } else if (deviceType == AudioDeviceType.Wave) { result = GetWaveAudioDevices(dataFlow); } else if (deviceType == AudioDeviceType.DirectSound) { result = GetDirectSoundAudioDevices(dataFlow); } else if (deviceType == AudioDeviceType.ASIO) { result = GetASIOAudioDevices(dataFlow); } else { throw new ArgumentException(String.Format("Invalid device type: {0}", deviceType), nameof(deviceType)); } return(result); }
public AudioOutputDevice(string name, string id, AudioDeviceType deviceType, bool defaultDevice) { Name = name; Id = id; DeviceType = deviceType; DefaultDevice = defaultDevice; }
public bool DeviceExists(string deviceName, AudioDeviceType deviceType = AudioDeviceType.Both) { bool hasDevice = false; HotkeyAudioDevice device = null; if ((deviceType == AudioDeviceType.Output || deviceType == AudioDeviceType.Both) && !hasDevice) { device = GetDevice(deviceName, AudioDeviceType.Output); if (device != null) { hasDevice = true; } } if ((deviceType == AudioDeviceType.Input || deviceType == AudioDeviceType.Both) && !hasDevice) { device = GetDevice(deviceName, AudioDeviceType.Input); if (device != null) { hasDevice = true; } } return(hasDevice); }
public AudioDeviceWatcher(AudioDeviceType ioType, CoreDispatcher dispatcher) { this.DeviceInformationList = new ObservableCollection <DeviceInformation>(); m_coreDispatcher = dispatcher; switch (ioType) { case AudioDeviceType.Input: { m_deviceSelectorString = MediaDevice.GetAudioCaptureSelector(); break; } case AudioDeviceType.Output: { m_deviceSelectorString = MediaDevice.GetAudioRenderSelector(); break; } default: { break; } } m_deviceWatcher = DeviceInformation.CreateWatcher(m_deviceSelectorString); m_deviceWatcher.Added += DeviceWatcher_Added; m_deviceWatcher.Removed += DeviceWatcher_Removed; m_deviceWatcher.Updated += DeviceWatcher_Updated; m_deviceWatcher.EnumerationCompleted += DeviceWatcher_EnumerationCompleted; m_deviceType = ioType; }
public IAudioDevice CreateDevice(AudioDeviceType audioDeviceType) { switch (audioDeviceType) { case AudioDeviceType.Silent: return new SilentAudioDevice(); case AudioDeviceType.Bass: return new BassAudioDevice(); default: throw new AudioDeviceException("unknown audio device type"); } }
public bool SetHotkeyCombination(HotKeys hotkeys, AudioDeviceType deviceType) { using (AppLogger.Log.InfoCall()) { HotKeys confHotKeys = null; switch (deviceType) { case AudioDeviceType.Playback: confHotKeys = AppConfigs.Configuration.PlaybackHotKeys; break; case AudioDeviceType.Recording: confHotKeys = AppConfigs.Configuration.RecordingHotKeys; break; default: throw new ArgumentOutOfRangeException(nameof(deviceType), deviceType, null); } using (AppLogger.Log.InfoCall()) { AppLogger.Log.Info("Unregister previous hotkeys", confHotKeys); WindowsAPIAdapter.UnRegisterHotKey(confHotKeys); AppLogger.Log.Info("Unregistered previous hotkeys", confHotKeys); if (hotkeys.Enabled && !WindowsAPIAdapter.RegisterHotKey(hotkeys)) { AppLogger.Log.Warn("Can't register new hotkeys", hotkeys); ErrorTriggered?.Invoke(this, new ExceptionEvent(new Exception("Impossible to register HotKey: " + hotkeys))); return(false); } AppLogger.Log.Info("New Hotkeys registered", hotkeys); } switch (deviceType) { case AudioDeviceType.Playback: AppConfigs.Configuration.PlaybackHotKeys = hotkeys; break; case AudioDeviceType.Recording: AppConfigs.Configuration.RecordingHotKeys = hotkeys; break; default: throw new ArgumentOutOfRangeException(nameof(deviceType), deviceType, null); } AppConfigs.Configuration.Save(); return(true); } }
/// <summary> /// Cycles the active device to the next device. Returns true if succesfully switched (at least /// as far as we can tell), returns false if could not successfully switch. Throws NoDevicesException /// if there are no devices configured. /// </summary> public bool CycleActiveDevice(AudioDeviceType type) { using (AppLogger.Log.InfoCall()) { try { return(_deviceCyclerManager.CycleDevice(type)); } catch (Exception exception) { ErrorTriggered?.Invoke(this, new ExceptionEvent(exception)); } return(false); } }
public HotkeyAudioDevice GetDevice(string deviceName, AudioDeviceType deviceType = AudioDeviceType.Output) { if (deviceType == AudioDeviceType.Output) { return(AudioOutputDevices.FirstOrDefault(audioDevice => audioDevice.AudioDeviceName.Equals(deviceName))); } else if (deviceType == AudioDeviceType.Input) { return(AudioInputDevices.FirstOrDefault(audioDevice => audioDevice.AudioDeviceName.Equals(deviceName))); } else if (deviceType == AudioDeviceType.Both) { throw new Exception("Cannot use device type of both to get one device"); } return(null); }
private void UpdateImageContextMenu(AudioDeviceType audioDeviceType, DeviceDefaultChangedEvent audioChangeEvent) { if (audioChangeEvent.role != Role.Console) { return; } foreach ( var toolStripDevItem in _selectionMenu.Items.OfType <ToolStripDeviceItem>().Where(item => item.AudioDevice.Type == audioDeviceType)) { toolStripDevItem.Image = toolStripDevItem.AudioDevice.FriendlyName == audioChangeEvent.device.FriendlyName ? Resources.Check : null; } }
/// <summary> /// Creates a new <see cref="AudioDeviceCapabilities"/> object. /// </summary> /// <param name="devType">The device type.</param> /// <param name="outputConfigurations">The available output configurations.</param> /// <param name="inputConfigurations">The available input configurations.</param> public AudioDeviceCapabilities(AudioDeviceType devType, IAudioConfiguration[] outputConfigurations, IAudioConfiguration[] inputConfigurations) { Type = devType; if (outputConfigurations == null) { outputConfigurations = new IAudioConfiguration[0]; } if (inputConfigurations == null) { inputConfigurations = new IAudioConfiguration[0]; } m_OutputConfigurations = outputConfigurations; m_InputConfigurations = inputConfigurations; }
/// <summary> /// Creates a new <see cref="AudioDeviceCapabilities"/> object. /// </summary> /// <param name="devType"></param> /// <param name="configurations"></param> public AudioDeviceCapabilities(AudioDeviceType devType, params IAudioConfiguration[] configurations) { Type = devType; if (configurations == null) { configurations = new IAudioConfiguration[0]; } if ((Type & AudioDeviceType.Input) != 0) { m_InputConfigurations = configurations; } if ((Type & AudioDeviceType.Output) != 0) { m_OutputConfigurations = configurations; } }
/// <summary> /// Cycles the active device to the next device. Returns true if succesfully switched (at least /// as far as we can tell), returns false if could not successfully switch. Throws NoDevicesException /// if there are no devices configured. /// </summary> public bool CycleActiveDevice(AudioDeviceType type) { using (AppLogger.Log.InfoCall()) { ICollection <IAudioDevice> list = null; string lastActive = null; switch (type) { case AudioDeviceType.Playback: list = AvailablePlaybackDevices; lastActive = AppConfigs.Configuration.LastPlaybackActive; break; case AudioDeviceType.Recording: list = AvailableRecordingDevices; lastActive = AppConfigs.Configuration.LastRecordingActive; break; default: throw new ArgumentOutOfRangeException(nameof(type), type, null); } switch (list.Count) { case 0: ErrorTriggered?.Invoke(this, new ExceptionEvent(new NoDevicesException())); return(false); case 1: return(false); } AppLogger.Log.Info("Cycle Audio Devices", list); var defaultDev = list.FirstOrDefault(device => device.FriendlyName == lastActive) ?? list.FirstOrDefault(device => device.IsDefault(Role.Console)) ?? list.ElementAt(0); var next = list.SkipWhile((device, i) => device != defaultDev).Skip(1).FirstOrDefault() ?? list.ElementAt(0); AppLogger.Log.Info("Select AudioDevice", next); return(SetActiveDevice(next)); } }
public static AudioDevice[] GetAudioDevices(AudioDeviceType audioDeviceType) { AudioDevice[] audioDevices = null; unsafe { TestStruct** structs; int devicesCount; GetAudioDevices(audioDeviceType, out structs, out devicesCount); audioDevices = new AudioDevice[devicesCount]; for (int i = 0; i < devicesCount; ++i) { AudioDevice audioDevice = new AudioDevice { Id = Marshal.PtrToStringUni(structs[i]->Id), Description = Marshal.PtrToStringUni(structs[i]->Description) }; audioDevices[i] = audioDevice; } DisposeAudioDevices(structs, devicesCount); } return audioDevices; }
public void SetAudioDeviceType(AudioDeviceType devicetype) { OutputMedia.AudioDeviceType = devicetype; }
/// <summary> /// Gets Audio render devices. /// </summary> /// <param name="deviceType">Audio device type.</param> /// <param name="deviceRole">Audio device role.</param> /// <returns>Audio device list.</returns> public static AudioDevice[] GetAudioRenderDevices(AudioDeviceType deviceType = AudioDeviceType.WASAPI, AudioDeviceRole deviceRole = AudioDeviceRole.Multimedia) { return(GetAudioDevices(AudioDataFlow.Render, deviceType, deviceRole)); }
public void SetAudioDeviceType(AudioDeviceType devicetype) { OutputMedia.AudioDeviceType = devicetype; }
public DeviceListChanged(IEnumerable <string> seletedDevicesList, AudioDeviceType type) { SeletedDevicesList = seletedDevicesList; Type = type; }
private unsafe static extern void GetAudioDevices(AudioDeviceType audioDeviceType, out TestStruct** structs, out int deviceType);
public static extern int GetAudioDevice( [InAttribute()][MarshalAsAttribute(UnmanagedType.LPStr)] string device, AudioDeviceType deviceType, [In, Out, MarshalAsAttribute(UnmanagedType.LPStr)] System.Text.StringBuilder audioDevice, int length);
public static extern int SetAudioDevice( [InAttribute()][MarshalAsAttribute(UnmanagedType.LPStr)] string device, AudioDeviceType deviceType, [InAttribute()][MarshalAsAttribute(UnmanagedType.LPStr)] string audioDevice);
public AudioDeviceWatcher(AudioDeviceType ioType, Windows.UI.Core.CoreDispatcher dispatcher) { m_deviceType = ioType; m_coreDispatcher = dispatcher; StartWatcher(); }
internal static extern int GetDeviceType(IntPtr device, out AudioDeviceType type);
/// <summary> /// Get the next device that need to be set as Default /// </summary> /// <param name="audioDevices"></param> /// <param name="type"></param> /// <returns></returns> protected IAudioDevice GetNextDevice(ICollection <IAudioDevice> audioDevices, AudioDeviceType type) { IAudioDevice lastDevice; _lastDevices.TryGetValue(type, out lastDevice); var defaultDev = lastDevice ?? audioDevices.FirstOrDefault(device => device.IsDefault(Role.Console)) ?? audioDevices.Last(); var next = audioDevices.SkipWhile((device, i) => !Equals(device, defaultDev)).Skip(1).FirstOrDefault() ?? audioDevices.ElementAt(0); return(next); }
/// <summary> /// Cycles the active device to the next device. Returns true if succesfully switched (at least /// as far as we can tell), returns false if could not successfully switch. Throws NoDevicesException /// if there are no devices configured. /// </summary> public bool CycleActiveDevice(AudioDeviceType type) { using (AppLogger.Log.InfoCall()) { ICollection<IAudioDevice> list = null; string lastActive = null; switch (type) { case AudioDeviceType.Playback: list = AvailablePlaybackDevices; lastActive = AppConfigs.Configuration.LastPlaybackActive; break; case AudioDeviceType.Recording: list = AvailableRecordingDevices; lastActive = AppConfigs.Configuration.LastRecordingActive; break; default: throw new ArgumentOutOfRangeException(nameof(type), type, null); } switch (list.Count) { case 0: ErrorTriggered?.Invoke(this, new ExceptionEvent(new NoDevicesException())); return false; case 1: return false; } AppLogger.Log.Info("Cycle Audio Devices", list); var defaultDev = list.FirstOrDefault(device => device.FriendlyName == lastActive) ?? list.FirstOrDefault(device => device.IsDefault(Role.Console)) ?? list.ElementAt(0); var next = list.SkipWhile((device, i) => device != defaultDev).Skip(1).FirstOrDefault() ?? list.ElementAt(0); AppLogger.Log.Info("Select AudioDevice", next); return SetActiveDevice(next); } }
public AudioOutputDevice(string name, string id, AudioDeviceType type) { Name = name; Id = id; DeviceType = type; }
public bool SetHotkeyCombination(HotKeys hotkeys, AudioDeviceType deviceType) { using (AppLogger.Log.InfoCall()) { HotKeys confHotKeys = null; switch (deviceType) { case AudioDeviceType.Playback: confHotKeys = AppConfigs.Configuration.PlaybackHotKeys; break; case AudioDeviceType.Recording: confHotKeys = AppConfigs.Configuration.RecordingHotKeys; break; default: throw new ArgumentOutOfRangeException(nameof(deviceType), deviceType, null); } AppLogger.Log.Info("Unregister previous hotkeys", confHotKeys); WindowsAPIAdapter.UnRegisterHotKey(confHotKeys); if (!WindowsAPIAdapter.RegisterHotKey(hotkeys)) { AppLogger.Log.Warn("Can't register new hotkeys", hotkeys); ErrorTriggered?.Invoke(this, new ExceptionEvent(new Exception("Impossible to register HotKey: " + hotkeys))); return false; } AppLogger.Log.Info("New Hotkeys registered", hotkeys); switch (deviceType) { case AudioDeviceType.Playback: AppConfigs.Configuration.PlaybackHotKeys = hotkeys; break; case AudioDeviceType.Recording: AppConfigs.Configuration.RecordingHotKeys = hotkeys; break; default: throw new ArgumentOutOfRangeException(nameof(deviceType), deviceType, null); } AppConfigs.Configuration.Save(); return true; } }
private void UpdateImageContextMenu(AudioDeviceType audioDeviceType, DeviceDefaultChangedEvent audioChangeEvent) { if (audioChangeEvent.role != Role.Console) return; foreach ( var toolStripDevItem in _selectionMenu.Items.OfType<ToolStripDeviceItem>().Where(item => item.AudioDevice.Type == audioDeviceType)) { toolStripDevItem.Image = toolStripDevItem.AudioDevice.FriendlyName == audioChangeEvent.device.FriendlyName ? Resources.Check : null; } }
/// <summary> /// Cycle the audio device for the given type /// </summary> /// <param name="type"></param> public abstract bool CycleAudioDevice(AudioDeviceType type);
public DeviceListChanged(IEnumerable<string> seletedDevicesList, AudioDeviceType type) { SeletedDevicesList = seletedDevicesList; Type = type; }
/// <summary> /// Cycles the active device to the next device. Returns true if succesfully switched (at least /// as far as we can tell), returns false if could not successfully switch. Throws NoDevicesException /// if there are no devices configured. /// </summary> public bool CycleActiveDevice(AudioDeviceType type) { using (AppLogger.Log.InfoCall()) { try { return _deviceCyclerManager.CycleDevice(type); } catch (Exception exception) { ErrorTriggered?.Invoke(this, new ExceptionEvent(exception)); } return false; } }
/// <summary> /// Cycle the audio device /// </summary> /// <param name="type"></param> public bool CycleDevice(AudioDeviceType type) { return(_deviceCyclerFactory.Get(CurrentCycler).CycleAudioDevice(type)); }
private void ValidateStringIsDeviceName(string deviceName, ValidationResult result, AudioDeviceType deviceType = AudioDeviceType.Both) { bool deviceExists = MainAudio.Instance.DeviceExists(deviceName, deviceType); if (!deviceExists) { result.Errors.Add(new ValidationException("This selected device does not exist")); result.Status = ValidationResultStatus.Error; } }