public MainForm() { library = Library.Load(); if (library == null) { library = new Library(); library.Save(); } library.LibraryChanged += library_LibraryChanged; settings = Settings.Load(SETTINGSPATH); if (settings == null) settings = new Settings(); MMDeviceEnumerator enumerator = new MMDeviceEnumerator(); defaultAudioDevice = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Console); this.musicPlayer.OpenCompleted += equalizerSettings_ShouldSet; this.equalizerSettings = EqualizerSettings.Load(EQUALIZERPATH); if (this.equalizerSettings == null) { this.equalizerSettings = new EqualizerSettings(); this.equalizerSettings.Save(EQUALIZERPATH); } this.equalizerSettings.ValueChanged += equalizerSettings_ShouldSet; SetUpGlobalHotkeys(); InitializeComponent(); }
private void RefreshDevices() { deviceList.Items.Clear(); using (var deviceEnumerator = new MMDeviceEnumerator()) using (var deviceCollection = deviceEnumerator.EnumAudioEndpoints( CaptureMode == CaptureMode.Capture ? DataFlow.Capture : DataFlow.Render, DeviceState.Active)) { foreach (var device in deviceCollection) { var deviceFormat = WaveFormatFromBlob(device.PropertyStore[ new PropertyKey(new Guid(0xf19f064d, 0x82c, 0x4e27, 0xbc, 0x73, 0x68, 0x82, 0xa1, 0xbb, 0x8e, 0x4c), 0)].BlobValue); var item = new ListViewItem(device.FriendlyName) {Tag = device}; item.SubItems.Add(deviceFormat.Channels.ToString(CultureInfo.InvariantCulture)); deviceList.Items.Add(item); } } }
private static MMDevice GetDefaultDevice() { using (var enumerator = new MMDeviceEnumerator()) { try { return enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia); } catch (CoreAudioAPIException) { return null; } } }
public void InitManager() { deviceEnum = new MMDeviceEnumerator(); deviceEnum.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia); device = deviceEnum.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia); sessionManager = AudioSessionManager2.FromMMDevice(device); }
/// <summary> /// Generates a collection of audio endpoint devices that meet the specified criteria. /// </summary> /// <param name="dataFlow">The data-flow direction for the endpoint device.</param> /// <param name="stateMask">The state or states of the endpoints that are to be included in the collection.</param> /// <returns><see cref="MMDeviceCollection"/> which contains the enumerated devices.</returns> public static MMDeviceCollection EnumerateDevices(DataFlow dataFlow, DeviceState stateMask) { using (var enumerator = new MMDeviceEnumerator()) { return enumerator.EnumAudioEndpoints(dataFlow, stateMask); } }
public IEnumerable<MMDevice> EnumerateWasapiDevices() { using (MMDeviceEnumerator enumerator = new MMDeviceEnumerator()) { return enumerator.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active); } }
public MMNotificationClient(MMDeviceEnumerator enumerator) { if (enumerator == null) throw new ArgumentNullException("enumerator"); Initialize(enumerator); }
public MMNotificationClient() { using (var e = new MMDeviceEnumerator()) { Initialize(e); } }
public static MMDevice GetDefaultSoundDevice() { using (var enumerator = new MMDeviceEnumerator()) { return enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Console); } }
/// <summary> /// Returns the default audio endpoint for the specified data-flow direction and role. /// </summary> /// <param name="dataFlow">The data-flow direction for the endpoint device.</param> /// <param name="role">The role of the endpoint device.</param> /// <returns><see cref="MMDevice"/> instance of the endpoint object for the default audio endpoint device.</returns> public static MMDevice DefaultAudioEndpoint(DataFlow dataFlow, Role role) { using (var enumerator = new MMDeviceEnumerator()) { return enumerator.GetDefaultAudioEndpoint(dataFlow, role); } }
private static AudioSessionManager2 GetDefaultAudioSessionManager2(DataFlow dataFlow) { using CSCore.CoreAudioAPI.MMDeviceEnumerator enumerator = new CSCore.CoreAudioAPI.MMDeviceEnumerator(); using var device = enumerator.GetDefaultAudioEndpoint(dataFlow, Role.Multimedia); var sessionManager = AudioSessionManager2.FromMMDevice(device); return(sessionManager); }
public CsCoreEngine() { using (var enumerator = new MMDeviceEnumerator()) { device = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Console); } endpointVolume = AudioEndpointVolume.FromDevice(device); }
private AudioSessionManager2 GetDefaultAudioSessionManager2(DataFlow dataFlow) { using (var enumerator = new MMDeviceEnumerator()) { using (var device = enumerator.GetDefaultAudioEndpoint(dataFlow, Role.Multimedia)) { var sessionManager = AudioSessionManager2.FromMMDevice(device); return sessionManager; } } }
public void CanAccessPropertyStore() { using (var enumerator = new MMDeviceEnumerator()) using (var collection = enumerator.EnumAudioEndpoints(DataFlow.All, DeviceState.All)) { Utils.DumpCollection(collection); enumerator.Dispose(); collection.Dispose(); } }
public void CanCreateDeviceNotificationEvent() { using (var enumerator = new MMDeviceEnumerator()) using (var notification = new MMNotificationClient(enumerator)) { notification.DefaultDeviceChanged += (s, e) => { }; notification.DeviceAdded += (s, e) => { }; notification.DevicePropertyChanged += (s, e) => { }; notification.DeviceRemoved += (s, e) => { }; notification.DeviceStateChanged += (s, e) => { }; } }
public static AudioClient CreateDefaultRenderClient() { using (var enumerator = new MMDeviceEnumerator()) { using (var device = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Console)) { var audioClient = AudioClient.FromMMDevice(device); Assert.IsNotNull(audioClient); return audioClient; } } }
public MusicPlayer() { using (var enumerator = new MMDeviceEnumerator()) { device = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia); using (var client = AudioClient.FromMMDevice(device)) { client.Initialize(AudioClientShareMode.Shared, AudioClientStreamFlags.None, 1000, 0, client.GetMixFormat(), Guid.Empty); } } }
public void CanEnumerateCaptureDevices() { using (var enumerator = new MMDeviceEnumerator()) using (var collection = enumerator.EnumAudioEndpoints(DataFlow.Capture, DeviceState.All)) { foreach (var item in collection) { Debug.WriteLine(item.ToString()); item.Dispose(); } enumerator.Dispose(); collection.Dispose(); } }
public void CanCreateAudioSessionManager2() { using (var enumerator = new MMDeviceEnumerator()) { using (var collection = enumerator.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active)) { foreach (var device in collection) { using (var sessionManager = AudioSessionManager2.FromMMDevice(device)) { Assert.IsNotNull(sessionManager); } } } } }
/// <summary> /// Tries the get device associated with the <see cref="DeviceId"/>. /// </summary> /// <param name="device">The device associated with the <see cref="DeviceId"/>. If the return value is <c>false</c>, the <paramref name="device"/> will be null.</param> /// <returns><c>true</c> if the associated device be successfully retrieved; false otherwise.</returns> public bool TryGetDevice(out MMDevice device) { try { using (var deviceEnumerator = new MMDeviceEnumerator()) { device = deviceEnumerator.GetDevice(DeviceId); } return true; } catch (Exception) { device = null; } return false; }
public static float GetSpotifyInstaVolume() { using (var enumerator = new CSCore.CoreAudioAPI.MMDeviceEnumerator()) using (var device = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia)) using (var sessionManager = AudioSessionManager2.FromMMDevice(device)) using (var sessionEnumerator = sessionManager.GetSessionEnumerator()) { foreach (var session in sessionEnumerator) { using (var audioMeterInformation = session.QueryInterface <AudioMeterInformation>()) using (var audioIdInformation = session.QueryInterface <AudioSessionControl2>()) { if (audioIdInformation.SessionIdentifier.Contains("Spotify")) { return(audioMeterInformation.GetPeakValue()); } } } } return(float.NaN); }
public void GetDefaultRenderEndpoint() { using (var enumerator = new MMDeviceEnumerator()) { using (var device = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Console)) { Debug.WriteLine(device.ToString()); } } }
private void Initialize(MMDeviceEnumerator enumerator) { int result = enumerator.RegisterEndpointNotificationCallbackNative(this); CoreAudioAPIException.Try(result, "IMMDeviceEnumerator", "RegisterEndpointNotificationCallback"); }
private void LoadSoundOutModes() { SoundOutModes.Clear(); using (var enumerator = new MMDeviceEnumerator()) { MMDevice defaultDevice; try { defaultDevice = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia); } catch (CoreAudioAPIException) { defaultDevice = null; } if (WasapiOut.IsSupportedOnCurrentPlatform) { var wasApiMode = new SoundOutMode("WASAPI", SoundOutType.WasApi, GetWasApiSoundOutDeviceById, GetWasApiSoundOut, new SoundOutDevice("Windows Default", WindowsDefaultId, SoundOutType.WasApi)); using (var devices = enumerator.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active)) { foreach (var device in devices.Select(x => new SoundOutDevice(x.FriendlyName, x.DeviceID, SoundOutType.WasApi, defaultDevice != null && defaultDevice.DeviceID == x.DeviceID))) wasApiMode.Devices.Add(device); } UpdateWindowsDefault(wasApiMode); SoundOutModes.Add(wasApiMode); } var directSoundMode = new SoundOutMode("DirectSound", SoundOutType.DirectSound, GetDirectSoundOutDeviceById, GetDirectSoundOut, new SoundOutDevice("Windows Default", WindowsDefaultId, SoundOutType.DirectSound)); foreach (var device in DirectSoundDeviceEnumerator.EnumerateDevices().Select(x => new SoundOutDevice(x.Description, x.Module, SoundOutType.DirectSound, defaultDevice != null && x.Description == defaultDevice.FriendlyName))) directSoundMode.Devices.Add(device); UpdateWindowsDefault(directSoundMode); SoundOutModes.Add(directSoundMode); CheckCurrentState(); } }
private static ISoundOut GetWasApiSoundOut(ISoundOutDevice device) { MMDevice mmDevice = null; if (device.Id == WindowsDefaultId) { mmDevice = GetDefaultDevice(); } if (mmDevice == null) { using (var enumerator = new MMDeviceEnumerator()) { using (var devices = enumerator.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active)) { if (devices == null || devices.Count == 0) throw new NoDeviceFoundException(); mmDevice = devices.FirstOrDefault(x => x.DeviceID == device.Id) ?? GetDefaultDevice() ?? devices.First(); } } } return new WasapiOut { Device = mmDevice,UseChannelMixingMatrices = false }; }
private void Form1_Load(object sender, EventArgs e) { using (var mmdeviceEnumerator = new MMDeviceEnumerator()) { using ( var mmdeviceCollection = mmdeviceEnumerator.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active)) { foreach (var device in mmdeviceCollection) { _devices.Add(device); } } } comboBox1.DataSource = _devices; comboBox1.DisplayMember = "FriendlyName"; comboBox1.ValueMember = "DeviceID"; }
private static ISoundOutDevice GetWasApiSoundOutDeviceById(string id) { using (var mmdeviceEnumerator = new MMDeviceEnumerator()) { using (var device = mmdeviceEnumerator.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active) .FirstOrDefault(x => x.DeviceID == id)) { return device == null ? null : new SoundOutDevice(device.FriendlyName, device.DeviceID, SoundOutType.WasApi); } } }
public void Slider() { try { using (var enumerator = new CSCore.CoreAudioAPI.MMDeviceEnumerator()) { // update volume for first start dynamic icon //volume = (float)(Math.Floor((potVal / 3 * 2.395)) / 100); while (true) { if (contVal != oldContVal) { // update value oldContVal = contVal; if (appEnd != null) { appEnd.Dispose(); } appEnd = getProcessAudioEndpoint(enumerator); // notify editing volume on another app if (settings.notifyApp) { nanoSliderTray.appVolume(getApp()); } } if (potVal != oldPotVal && (potVal > oldPotVal + 1 || potVal < oldPotVal - 1)) // prevents ghost slides { oldPotVal = potVal; volume = (float)(Math.Floor((potVal / 3 * 2.395)) / 100); nanoSliderTray.DynamicIcon(volume); if (contVal == defaultOutputSink) { ChangeOutputVolume(volume, enumerator); } else if (contVal == defaultInputSink) { ChangeInputVolume(volume, enumerator); } else { ChangeAppVolume(volume); } } if (nanoID == -1) { // if nano undetected poll slower NanoFind(); Thread.Sleep(1000); } else { NanoFind(); Thread.Sleep(100); } } } } catch (Exception k) { Console.WriteLine(k); } }
private void UpdateDefaultAudioDevice() { MMDevice defaultAudioEndpoint; using (var enumerator = new MMDeviceEnumerator()) { defaultAudioEndpoint = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia); } foreach (var soundOutMode in SoundOutModes) { foreach (var soundOutDevice in soundOutMode.Devices) soundOutDevice.IsDefault = false; var newDefaultDevice = soundOutMode.Devices.FirstOrDefault(x => x.Id == defaultAudioEndpoint.DeviceID); if (newDefaultDevice != null) newDefaultDevice.IsDefault = true; } }
private CSCore.CoreAudioAPI.AudioSessionManager2 GetDefaultAudioSessionManager2(CSCore.CoreAudioAPI.MMDeviceEnumerator enumerator, CSCore.CoreAudioAPI.DataFlow dataFlow) { using (var device = enumerator.GetDefaultAudioEndpoint(dataFlow, CSCore.CoreAudioAPI.Role.Multimedia)) { var sessionManager = CSCore.CoreAudioAPI.AudioSessionManager2.FromMMDevice(device); return(sessionManager); } }
/// <summary> /// Initializes a new instance of the <see cref="MMNotificationClient"/> class. /// </summary> public MMNotificationClient() { _deviceEnumerator = new MMDeviceEnumerator(); Initialize(_deviceEnumerator); }
private void ChooseSoundDevice() { using (MMDeviceEnumerator enumerator = new MMDeviceEnumerator()) { if (soundOut is WasapiOut) { ((WasapiOut)soundOut).Device = enumerator.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active)[0]; } else { ((DirectSoundOut)soundOut).Device = DirectSoundDeviceEnumerator.EnumerateDevices().First().Guid; } } }
private AudioSessionManager2 GetDefaultAudioSessionManager2(DataFlow dataFlow) { using (var enumerator = new MMDeviceEnumerator()) { using (var device = enumerator.GetDefaultAudioEndpoint(dataFlow, Role.Multimedia)) { Debug.WriteLine("DefaultDevice: " + device.FriendlyName); var sessionManager = AudioSessionManager2.FromMMDevice(device); return sessionManager; } } }
public static List<MMDevice> GetSoundDevices() { List<MMDevice> devices = new List<MMDevice>(); using (var mmdeviceEnumerator = new MMDeviceEnumerator()) { using (var mmdeviceCollection = mmdeviceEnumerator.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active)) { foreach (var device in mmdeviceCollection) { devices.Add(device); } } } return devices; }