/**
  * Mutes/Unmutes Spotify.
  *
  * i: false = unmute, true = mute
  **/
 private void Mute(bool mute)
 {
     AudioUtils.SetMute(hook.VolumeControl.Control, mute);
     muted = AudioUtils.IsMuted(hook.VolumeControl.Control);
 }
        /**
         * Contains the logic for when to mute Spotify
         **/
        private void MainTimer_Tick(object sender, EventArgs e)
        {
            try {
                if (hook.IsRunning())
                {
                    muted = muted ?? AudioUtils.IsMuted(hook.VolumeControl.Control);

                    if (hook.IsAdPlaying())
                    {
                        if (MainTimer.Interval != 1000)
                        {
                            MainTimer.Interval = 1000;
                        }
                        if (muted == false)
                        {
                            Mute(true);
                        }
                        if (!hook.IsPlaying())
                        {
                            AudioUtils.SendNextTrack(hook.Handle == IntPtr.Zero ? Handle : hook.Handle);
                            Thread.Sleep(500);
                        }

                        string artist  = hook.GetArtist();
                        string message = Properties.strings.StatusMuting + " " + Truncate(artist);
                        if (lastMessage != message)
                        {
                            lastMessage      = message;
                            StatusLabel.Text = message;
                            artistTooltip.SetToolTip(StatusLabel, artist);
                            LogAction("/mute/" + artist);
                        }
                    }
                    else if (hook.IsPlaying() && !hook.WindowName.Equals("Spotify")) // Normal music
                    {
                        if (muted == true)
                        {
                            Thread.Sleep(500); // Give extra time for ad to change out
                            Mute(false);
                        }
                        if (MainTimer.Interval != 400)
                        {
                            MainTimer.Interval = 400;
                        }

                        string artist  = hook.GetArtist();
                        string message = Properties.strings.StatusPlaying + " " + Truncate(artist);
                        if (lastMessage != message)
                        {
                            lastMessage      = message;
                            StatusLabel.Text = message;
                            artistTooltip.SetToolTip(StatusLabel, artist);
                            LogAction("/play/" + artist);
                        }
                    }
                    else if (hook.WindowName.Equals("Spotify"))
                    {
                        string message = Properties.strings.StatusPaused;
                        if (lastMessage != message)
                        {
                            lastMessage      = message;
                            StatusLabel.Text = message;
                            artistTooltip.SetToolTip(StatusLabel, "");
                        }
                    }
                }
                else
                {
                    if (MainTimer.Interval != 1000)
                    {
                        MainTimer.Interval = 1000;
                    }
                    string message = Properties.strings.StatusNotFound;
                    if (lastMessage != message)
                    {
                        lastMessage      = message;
                        StatusLabel.Text = message;
                        artistTooltip.SetToolTip(StatusLabel, "");
                    }
                    ;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
        }
예제 #3
0
 /**
  * Mutes/Unmutes Spotify.
  *
  * i: false = unmute, true = mute
  **/
 private void Mute(bool mute)
 {
     AudioUtils.SetMute(hook.VolumeControl.Control, mute);
     muted = AudioUtils.IsMuted(hook.VolumeControl.Control) != null ? (bool)AudioUtils.IsMuted(hook.VolumeControl.Control) : false;
 }