/**
         * 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);
            }
        }
Пример #2
0
        /**
         * Contains the logic for when to mute Spotify
         **/
        private void MainTimer_Tick(object sender, EventArgs e)
        {
            try {
                if (hook.IsRunning())
                {
                    Debug.WriteLine(AudioUtils.GetPeakVolume(hook.VolumeControl));
                    if (hook.IsAdPlaying())
                    {
                        if (MainTimer.Interval < 1500)
                        {
                            MainTimer.Interval = 1500;
                        }
                        if (!playingAd)
                        {
                            playingAd = true;
                        }
                        if (!muted)
                        {
                            Mute(true);
                        }

                        string artist = hook.GetArtist();
                        if (lastArtistName != artist)
                        {
                            StatusLabel.Text = "Muting: " + Truncate(artist);
                            artistTooltip.SetToolTip(StatusLabel, lastArtistName = artist);
                            LogAction("/mute/" + artist);
                        }
                    }
                    else if (hook.IsPlaying()) // Normal music
                    {
                        if (muted)
                        {
                            Mute(false);
                        }
                        if (MainTimer.Interval > 400)
                        {
                            MainTimer.Interval = 400;
                        }
                        if (playingAd)
                        {
                            playingAd = false;
                        }

                        string artist = hook.GetArtist();
                        if (lastArtistName != artist)
                        {
                            StatusLabel.Text = "Playing: " + Truncate(artist);
                            artistTooltip.SetToolTip(StatusLabel, lastArtistName = artist);
                            LogAction("/play/" + artist);
                        }
                    }
                    else
                    {
                        StatusLabel.Text = "Spotify is paused";
                        lastArtistName   = "";
                        artistTooltip.SetToolTip(StatusLabel, "");
                    }
                }
                else
                {
                    MainTimer.Interval = 5000;
                    StatusLabel.Text   = "Spotify is not running";
                    lastArtistName     = "";
                    artistTooltip.SetToolTip(StatusLabel, "");
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
        }