protected override void OnStart(string[] args) { SetServiceState(ServiceState.SERVICE_START_PENDING, 100000); _logger.Info("Service Started."); _controller.LoadDevices(false, false, false); _logger.Info("Successfully found {0} audio devices.", _controller.GetDevices().Count()); _selectedDevice = _controller.DefaultPlaybackDevice; if (_selectedDevice == null) { throw new InvalidOperationException("Error loading default playback device"); } _selectedDevice.ReloadAudioEndpointVolume(); _selectedDevice.VolumeChanged.Subscribe(this); _selectedDevice.MuteChanged.Subscribe(this); _logger.Info("Selected Default Audio Device ({0}) for volume tracking.", _selectedDevice.FullName); _requestTimer.OnTimer = _requestTimer_Elapsed; CommandStack.Add(new PowerChangeCommandItem(true)); CommandStack.Add(new LoadSceneCommandItem(3)); PerformCommandStack().Wait(); var volumeTask = _selectedDevice.GetVolumeAsync(); volumeTask.Wait(); CommandStack.Add(new VolumeChangeCommandItem(volumeTask.Result)); PerformCommandStack().Wait(); SetServiceState(ServiceState.SERVICE_RUNNING); }
private void Start() { var controller = new CoreAudioController(false); controller.LoadDevices(false, false, false); CoreAudioDevice defaultPlaybackDevice = controller.DefaultPlaybackDevice; defaultPlaybackDevice.ReloadAudioEndpointVolume(); defaultPlaybackDevice.VolumeChanged.Subscribe(this); Console.WriteLine("Press Enter to exit..."); Console.ReadLine(); }