public void UpdateAudioEndPointDevices() { DefaultEndPointDevice = AudioMMDevices.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia); AudioEndPointDevices = AudioMMDevices.EnumerateAudioEndPoints(DataFlow.Render, DeviceState.Active); AudioEndPointDevice = IsAudioEndPointDeviceIndexAvailable() ? AudioEndPointDevices[AudioEndPointDeviceIndex.Value] : DefaultEndPointDevice; AudioDeviceVolume = (int)(AudioEndPointDevice.AudioEndpointVolume.MasterVolumeLevelScalar * 100); }
private async Task SetSpotifyAudioSessionsAndProcessId(bool running) { _spotifyAudioSessionProcessId = null; while (running && _spotifyAudioSessionProcessId == null && _spotifyProcessesIds.Any()) { var sessionsAudioEndPointDevices = AudioMMDevices .EnumerateAudioEndPoints(DataFlow.Render, DeviceState.Active) .Select(x => x.AudioSessionManager.Sessions) .ToList(); lock (sessionsAudioEndPointDevices) { foreach (var sessionAudioEndPointDevice in sessionsAudioEndPointDevices) { for (var i = 0; i < sessionAudioEndPointDevice.Count; i++) { var currentAudioSessionControl = sessionAudioEndPointDevice[i]; var currentProcessId = (int)currentAudioSessionControl.GetProcessID; if (!IsSpotifyAudioSessionControl(currentProcessId)) { continue; } if (!SpotifyAudioSessionControls.Contains(currentAudioSessionControl)) { SpotifyAudioSessionControls.Add(currentAudioSessionControl); } _spotifyAudioSessionProcessId = currentProcessId; break; } if (_spotifyAudioSessionProcessId.HasValue) { break; } } } await Task.Delay(300); _spotifyProcessesIds = SpotifyProcess.GetSpotifyProcesses(_processManager).Select(x => x.Id).ToList(); } }