public void CreateDevice(EventHandler <DefaultDeviceChangedEventArgs> aDefaultDeviceChangedHandler, EventHandler <AudioEndpointVolumeCallbackEventArgs> aVolumeChangedHandler) { try { //Create device and register default device change notification _mMdeviceEnumerator = new MMDeviceEnumerator(); iMultiMediaNotificationClient = new MMNotificationClient(_mMdeviceEnumerator); iMultiMediaNotificationClient.DefaultDeviceChanged += iDefaultDeviceChangedHandler = aDefaultDeviceChangedHandler; var mMdeviceList = _mMdeviceEnumerator.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active); if (mMdeviceList != null && mMdeviceList.Count > 0) { _mMdevice = _mMdeviceEnumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia); GUIGraphicsContext.CurrentAudioRendererDevice = _mMdevice.FriendlyName; //Register to get volume modifications if (_mMdevice != null) { iAudioEndpointVolume = AudioEndpointVolume.FromDevice(_mMdevice); } iAudioEndpointVolumeMixerCallback = new CSCore.CoreAudioAPI.AudioEndpointVolumeCallback(); iAudioEndpointVolumeMixerCallback.NotifyRecived += iVolumeChangedHandler = aVolumeChangedHandler; iAudioEndpointVolume?.RegisterControlChangeNotify(iAudioEndpointVolumeMixerCallback); } // For audio session Stop(); //DispatchingTimerStart(); // Disable because the check will be done in IsMuted code } catch (Exception) { // When no device available } }
private void SetupDefaultEndpoint() { if (_endpointVolume != null) { _endpointVolume.UnregisterControlChangeNotify(_endpointVolumeCallback); _endpointVolume.Dispose(); } try { var defaultDevice = _deviceEnumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Console); _endpointVolume = AudioEndpointVolume.FromDevice(defaultDevice); _endpointVolume.RegisterControlChangeNotify(_endpointVolumeCallback); } catch (Exception ex) { _logger.Error(ex); } }
private void GetMMD() { M.D(1000, "GetMMD"); L.MMD = CSCore.CoreAudioAPI.MMDeviceEnumerator.TryGetDefaultAudioEndpoint(CSCore.CoreAudioAPI.DataFlow.Render, CSCore.CoreAudioAPI.Role.Multimedia); if (L.MMD == null) { M.D(1001, M.Kind.ER, "MMD=null"); return; } AEV = AudioEndpointVolume.FromDevice(L.MMD); AEVC = new AudioEndpointVolumeCallback(); AEVC.NotifyRecived += AEV_NotifyRecived; AEV.RegisterControlChangeNotify(AEVC); L.MSD = new MasterData(AEV.IsMuted, AEV.MasterVolumeLevelScalar); AMI = AudioMeterInformation.FromDevice(L.MMD); //M.D(1008); //TryGetSs(); M.D(1009); }
private void GetMMD() { DW(1000); L.MMD = CSCore.CoreAudioAPI.MMDeviceEnumerator.TryGetDefaultAudioEndpoint(CSCore.CoreAudioAPI.DataFlow.Render, CSCore.CoreAudioAPI.Role.Multimedia); if (L.MMD == null) { return; } AEV = AudioEndpointVolume.FromDevice(L.MMD); var aevc = new AudioEndpointVolumeCallback(); aevc.NotifyRecived += Mepv_NotifyRecived; AEV.RegisterControlChangeNotify(aevc); L.MD = new MasterData(AEV.IsMuted, AEV.MasterVolumeLevelScalar); AMI = AudioMeterInformation.FromDevice(L.MMD); TryGetSs(); }
private void SetPlaybackDevice() { _playbackDevice = _enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Console); if (_playbackDevice == null) { _logger.Warning("No audio device found with Console role"); return; } _audioEndpointVolume = AudioEndpointVolume.FromDevice(_playbackDevice); AudioEndpointVolumeCallback audioEndpointVolumeCallback = new AudioEndpointVolumeCallback(); audioEndpointVolumeCallback.NotifyRecived += (s, e) => { UpdateVolumeDataModel(); }; _audioEndpointVolume.RegisterControlChangeNotify(audioEndpointVolumeCallback); DataModel.DefaultDeviceName = _playbackDevice.FriendlyName; _logger.Information(string.Format("Playback device {0} registered to to fill Playback volume data model", _playbackDevice.FriendlyName)); }
/// <summary> /// /// </summary> /// <param name="aDefaultDeviceChangedHandler"></param> /// <param name="aVolumeChangedHandler"></param> public void Open(EventHandler <DefaultDeviceChangedEventArgs> aDefaultDeviceChangedHandler, EventHandler <AudioEndpointVolumeCallbackEventArgs> aVolumeChangedHandler) { //Create device and register default device change notification iMultiMediaDeviceEnumerator = new MMDeviceEnumerator(); iMultiMediaNotificationClient = new MMNotificationClient(iMultiMediaDeviceEnumerator); iMultiMediaNotificationClient.DefaultDeviceChanged += iDefaultDeviceChangedHandler = aDefaultDeviceChangedHandler; iMultiMediaDevice = iMultiMediaDeviceEnumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia); //Register to get volume modifications iAudioEndpointVolume = AudioEndpointVolume.FromDevice(iMultiMediaDevice); iAudioEndpointVolumeCallback = new AudioEndpointVolumeCallback(); iAudioEndpointVolumeCallback.NotifyRecived += iVolumeChangedHandler = aVolumeChangedHandler; iAudioEndpointVolume.RegisterControlChangeNotify(iAudioEndpointVolumeCallback); if (iVisualizerCount > 0) { // We probably got restarted, make sure visualization is running if needed StartAudioVisualization(); } }