Exemplo n.º 1
0
        private void HookSpotify()
        {
            try
            {
                _spotify = Process.GetProcessesByName("spotify")[0];
            }
            catch (IndexOutOfRangeException)
            {
                // spotify isn't running; hook ObjectCreate and wait for it to launch
                _objectCreateHook = new WinEventHook(OnObjectCreate, WinEventHook.EventConstant.EVENT_OBJECT_CREATE);
                return;
            }

            // in case Mutify has been launched while Spotify is playing something
            if (_currentTitle != null)
            {
                VolumeControl.SetApplicationMute(_spotify.Id, _blacklist.Contains(_currentTitle));
                MuteAdButton.IsEnabled = true;
            }

            _spotify.EnableRaisingEvents = true; // register a handler
            _spotify.Exited += SpotifyExited;    // for spotify's exit

            // hook changes to Spotify's main window title so titles can be checked against the blacklist
            _windowNameHook = new WinEventHook(OnWindowNameChange, WinEventHook.EventConstant.EVENT_OBJECT_NAMECHANGE, _spotify.Id);
        }
Exemplo n.º 2
0
        private void MuteAdButton_Click(object sender, EventArgs e) // was RoutedEventArgs.  Consequences?
        {
            var ad = _currentTitle;

            if (!_blacklist.Contains(ad))
            {
                _blacklist.Add(ad);
                _blacklistChanged = true;
            }

            VolumeControl.SetApplicationMute(_spotify.Id, true);
        }
Exemplo n.º 3
0
        private void OnWindowNameChange(IntPtr hWinEventHook, uint eventType,
                                        IntPtr hWnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime)
        {
            if (hWnd != _spotify.MainWindowHandle)
            {
                return;
            }

            if (_currentTitle == null) // nothing playing
            {
                this.MuteAdButton.IsEnabled = false;
            }
            else
            {
                this.MuteAdButton.IsEnabled = true;
                VolumeControl.SetApplicationMute(_spotify.Id, _blacklist.Contains(_currentTitle));
            }
        }