public void PlayCharacter(bool[] elements, PlayingProgress progress, CancellationToken cancellationToken)
        {
            List <Action> audioAction = generateMorseCodeAudioActionActionLetter(elements);

            ThreadPool.QueueUserWorkItem(new WaitCallback(PlayMorseCode),
                                         new object[] { audioAction, progress, cancellationToken });
        }
        public void PlayWords(List <List <bool[]> > words, PlayingProgress progress, CancellationToken cancellationToken)
        {
            List <Action> audioAction = generateMorseCodeAudioActions(words);

            ThreadPool.QueueUserWorkItem(new WaitCallback(PlayMorseCode),
                                         new object[] { audioAction, progress, cancellationToken });
        }
        void PlayMorseCode(object objects)
        {
            object[] objectArray = objects as object[];

            List <Action>     audioActions      = objectArray[0] as List <Action>;
            PlayingProgress   progress          = objectArray[1] as PlayingProgress;
            CancellationToken cancellationToken = (CancellationToken)objectArray[2];

            foreach (var audio in audioActions)
            {
                audio.Invoke();
                if (cancellationToken.IsCancellationRequested)
                {
                    break;
                }
            }
            OnMorseCodeFinishPlaying?.Invoke(this, new EventArgs());
        }
Exemple #4
0
        private void MainTimer_Tick(object sender, EventArgs e)
        {
            // Avoid simultaneous calls
            if (!isTimerDone)
            {
                return;
            }
            isTimerDone = false;

            try
            {
                if (Process.GetProcessesByName("spotify").Length < 1)
                {
                    if (exitTolerance > 10)
                    {
                        File.AppendAllText(logPath, "Spotify process not found\r\n");
                        MessageBox.Show("Spotify hasn't started or was manually closed, the application will exit.", "Closing", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        Application.Exit();
                    }
                    if (LB_Status.InvokeRequired)
                    {
                        LB_Status.Invoke(new MethodInvoker(delegate { LB_Status.Text = "Spotify not started"; }));
                    }

                    exitTolerance += 1;
                    isTimerDone    = true;
                    return;
                }
                else
                {
                    exitTolerance = 0;
                }

                WebHelperResult whr = WebHelperHook.GetStatus();

                if (whr.isAd) // Track is ad
                {
                    if (whr.isPlaying)
                    {
                        Debug.WriteLine("Ad is playing");
                        if (lastArtistName != whr.artistName)
                        {
                            lastArtistName = whr.artistName;
                            //LogAction("/mute/" + whr.artistName);
                            Debug.WriteLine("Blocked " + whr.artistName);
                        }
                    }
                    else // Ad is paused
                    {
                        Debug.WriteLine("Ad is paused");
                    }
                }
                else if (whr.isPrivateSession)
                {
                    if (lastArtistName != whr.artistName)
                    {
                        lastArtistName = whr.artistName;
                        MessageBox.Show("Please disable 'Private Session' on Spotify for EasyBlocker to function properly.", "EasyBlocker", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, (MessageBoxOptions)0x40000);
                    }
                }
                else if (!whr.isRunning)
                {
                    if (LB_Status.InvokeRequired)
                    {
                        LB_Status.Invoke(new MethodInvoker(delegate { LB_Status.Text = "SpotifyWebHelper nor started"; }));
                    }
                    File.AppendAllText(logPath, "Not running.\r\n");
                    timer.Interval = 5000;
                }
                else if (!whr.isPlaying)
                {
                    if (recordOnPlay && !recordWaiting)
                    {
                        StopCapture();
                        recordOnPlay  = false;
                        recordWaiting = false;
                    }

                    if (LB_Status.InvokeRequired)
                    {
                        LB_Status.Invoke(new MethodInvoker(delegate { LB_Status.Text = "Spotify paused"; }));
                    }
                    lastArtistName = "";
                    lastTrackName  = "";
                }
                else // Song is playing
                {
                    if ((whr.length - whr.position < 2) || (!whr.isPlaying && recordOnPlay))
                    {
                        timer.Interval = 300;
                    }
                    else if (timer.Interval != 1000)
                    {
                        timer.Interval = 1000;
                    }

                    if (lastArtistName != whr.artistName || lastTrackName != whr.trackName)
                    {
                        if (recordOnPlay)
                        {
                            if (!recordWaiting)
                            {
                                StopCapture();
                            }

                            StartCapture(savePath + "\\" + strToFile(whr.artistName + " - " + whr.trackName + ".wav"));
                            recordWaiting = false;

                            Task.Run(() => convertToMP3(true));
                            File.AppendAllText(mp3ID3Catalog, strToFile(whr.artistName + " - " + whr.trackName + ".wav") + "¤" + whr.trackName + "¤" + whr.artistName + "¤" + whr.albumName + "\n");
                        }

                        // Delegate refresh on track change
                        if (LB_Status.InvokeRequired)
                        {
                            LB_Status.Invoke(new MethodInvoker(delegate { LB_Status.Text = ShortenName("> " + whr.artistName + " - " + whr.trackName); }));
                        }
                        if (PlayingProgress.InvokeRequired)
                        {
                            PlayingProgress.Invoke(new MethodInvoker(delegate { PlayingProgress.Maximum = whr.length; }));
                        }
                        lastArtistName = whr.artistName;
                        lastTrackName  = whr.trackName;
                        lastAlbumName  = whr.albumName;
                    }

                    if (LB_Position.InvokeRequired)
                    {
                        LB_Position.Invoke(new MethodInvoker(delegate { LB_Position.Text = toTimeString(whr.position, whr.length); }));
                    }
                    Int32 minValue = (int)whr.position < whr.length ? (int)whr.position : whr.length;
                    if (PlayingProgress.InvokeRequired)
                    {
                        PlayingProgress.Invoke(new MethodInvoker(delegate { PlayingProgress.Value = minValue; }));
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                File.AppendAllText(logPath, ex.Message + '\n');
            }

            isTimerDone = true;
        }