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(); }
public void InitManager() { deviceEnum = new MMDeviceEnumerator(); deviceEnum.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia); device = deviceEnum.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia); sessionManager = AudioSessionManager2.FromMMDevice(device); }
public CsCoreEngine() { using (var enumerator = new MMDeviceEnumerator()) { device = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Console); } endpointVolume = AudioEndpointVolume.FromDevice(device); }
/// <summary> /// Creates a new AudioMeterInformation instance for the given device. /// </summary> /// <returns>AudioMeterInformation</returns> public static AudioMeterInformation FromDevice(MMDevice device) { if (device == null) throw new ArgumentNullException("device"); var ptr = device.Activate(new Guid("C02216F6-8C67-4B5B-9D00-D008E73E0064"), ExecutionContext.CLSCTX_ALL, IntPtr.Zero); return new AudioMeterInformation(ptr); }
public static AudioClient FromMMDevice(MMDevice device) { if (device == null) throw new ArgumentNullException("device"); IntPtr ptr; int result = device.ActivateNative(IID_IAudioClient, ExecutionContext.CLSCTX_ALL, IntPtr.Zero, out ptr); CoreAudioAPIException.Try(result, "IMMDevice", "Activate"); return new AudioClient(ptr); }
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 Open(string filename, MMDevice device) { CleanupPlayback(); _waveSource = CodecFactory.Instance.GetCodec(filename) .ToSampleSource() .ToMono() .ToWaveSource(); _soundOut = new WasapiOut() {Latency = 100, Device = device}; _soundOut.Initialize(_waveSource); if (PlaybackStopped != null) _soundOut.Stopped += PlaybackStopped; }
/// <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 void Open(string filename, MMDevice device) { CleanupPlayback(); var source = CodecFactory.Instance.GetCodec(filename); waveSource = CodecFactory.Instance.GetCodec(filename) .ToStereo() .ChangeSampleRate(44100) .ToSampleSource() .AppendSource(Equalizer.Create10BandEqualizer, out equalizer) .ToWaveSource(16); soundOut = new WasapiOut() {Latency = 100, Device = device}; soundOut.Initialize(waveSource); if (this.OpenCompleted != null) this.OpenCompleted(this, new EventArgs()); }
private void deviceList_SelectedIndexChanged(object sender, EventArgs e) { if (deviceList.SelectedItems.Count > 0) { SelectedDevice = (MMDevice) deviceList.SelectedItems[0].Tag; } else { SelectedDevice = null; } }
/// <summary> /// Returns a new <see cref="AudioEndpointVolume" /> instance based on a <see cref="MMDevice" /> instance. /// </summary> /// <param name="device"><see cref="MMDevice" /> instance to create the <see cref="AudioEndpointVolume" /> for.</param> /// <returns>A new <see cref="AudioEndpointVolume" /> instance based on the specified <paramref name="device" />.</returns> public static AudioEndpointVolume FromDevice(MMDevice device) { IntPtr ptr = device.Activate(new Guid("5CDF2C82-841E-4546-9722-0CF74078229A"), CLSCTX.CLSCTX_ALL, IntPtr.Zero); return new AudioEndpointVolume(ptr); }
/// <summary> /// Creates a new instance of <see cref="AudioSessionManager2"/> based on a <see cref="MMDevice"/>. /// </summary> /// <param name="device">Device to use to activate the <see cref="AudioSessionManager2"/>.</param> /// <returns><see cref="AudioSessionManager2"/> instance for the specified <paramref name="device"/>.</returns> // ReSharper disable once InconsistentNaming public static AudioSessionManager2 FromMMDevice(MMDevice device) { return new AudioSessionManager2(device.Activate(IID_IAudioSessionManager2, CLSCTX.CLSCTX_ALL, IntPtr.Zero)); }
/// <summary> /// Creates a new instance of <see cref="AudioSessionManager2"/> based on a <see cref="MMDevice"/>. /// </summary> /// <param name="device">Device to use to activate the <see cref="AudioSessionManager2"/>.</param> /// <returns><see cref="AudioSessionManager2"/> instance for the specified <paramref name="device"/>.</returns> // ReSharper disable once InconsistentNaming public static AudioSessionManager2 FromMMDevice(MMDevice device) { return(new AudioSessionManager2(device.Activate(IID_IAudioSessionManager2, CLSCTX.CLSCTX_ALL, IntPtr.Zero))); }
private void DeviceSetting_ApplyDevices(AForge.Video.DirectShow.FilterInfo cameraInfo, CSCore.CoreAudioAPI.MMDevice microphoneInfo, CSCore.CoreAudioAPI.MMDevice speakerInfo) { StopMedia(); StartMedia(cameraInfo, microphoneInfo, speakerInfo); }