private void AutoMute() { _mainSprotifyProcess?.Refresh(); if (_mainSprotifyProcess == null || _mainSprotifyProcess.HasExited) { GetSpotifyProcess(); } if (_mainSprotifyProcess == null) { return; } var currentTile = _mainSprotifyProcess.MainWindowTitle; if (currentTile?.Length > 60) { currentTile = currentTile?.Substring(0, 60); } if (!string.Equals(_lastSpotifyTitle, currentTile)) { txtCurrentPlaying.Text = currentTile; _lastSpotifyTitle = currentTile; notifyIcon.Text = currentTile; } _isSpotifyMuting = VolumeMixer.GetApplicationMute(_mainSprotifyProcess.Id) ?? true; var isAdvertisement = IsAdvertisement(currentTile); if (isAdvertisement && _isSpotifyMuting != true) { VolumeMixer.SetApplicationMute(_mainSprotifyProcess.Id, true); _totalBlockedAds++; txtAdsBlocked.Text = $"Ads blocked: {_totalBlockedAds:N0}"; btnMuteAction.Text = "Un-mute Spotify"; //Console.WriteLine("Mute"); txtCurrentPlaying.ForeColor = Color.Red; notifyIcon.Icon = Resources.notifyIconRed_Icon; } else if (!isAdvertisement && _isSpotifyMuting) { btnMuteAction.Text = "Mute Spotify"; Thread.Sleep(1_000); VolumeMixer.SetApplicationMute(_mainSprotifyProcess.Id, false); txtCurrentPlaying.ForeColor = Color.Green; notifyIcon.Icon = Resources.notifyIcon_Icon; } }
private void MuteSpotify() { chbAutoMute.Checked = false; if (_isSpotifyMuting) { _isSpotifyMuting = false; VolumeMixer.SetApplicationMute(_mainSprotifyProcess.Id, false); btnMuteAction.Text = "Mute Spotify"; txtCurrentPlaying.ForeColor = Color.Green; notifyIcon.Icon = (Icon) new System.ComponentModel.ComponentResourceManager(GetType()).GetObject("notifyIcon.Icon"); } else { _isSpotifyMuting = true; VolumeMixer.SetApplicationMute(_mainSprotifyProcess.Id, true); btnMuteAction.Text = "Un-mute Spotify"; txtCurrentPlaying.ForeColor = Color.Red; notifyIcon.Icon = (Icon) new System.ComponentModel.ComponentResourceManager(GetType()).GetObject("notifyIconRed.Icon"); } _appConfig.AutoMute = chbAutoMute.Checked; WriteConfig(); }