示例#1
0
        //========================================================================================
        // Methods
        //========================================================================================

        /// <summary>
        /// Asynchronously searches for the lyrics of the given song.
        /// </summary>
        /// <param name="song">An ISong specifying both the artist and title of the song.</param>

        public void RetrieveLyrics(ISong song)
        {
            // song could be null if we called this method just when switching tracks
            // yes a very small window but nonetheless..
            if (!isConnected || (song == null))
            {
                return;
            }

            int hash = song.GetHashCode();

            lock (engine)
            {
                if (!queue.ContainsKey(hash))
                {
                    var worker = new BackgroundWorker();
                    worker.DoWork                    += RetrieveLyrics;
                    worker.RunWorkerCompleted        += LyricsRetrieved;
                    worker.WorkerSupportsCancellation = true;

                    queue.Add(song.GetHashCode(), worker);

                    worker.RunWorkerAsync(song);
                }
            }
        }
示例#2
0
        private void DoLyricsProgressReport(ISong song, int stage)
        {
            if (!Dispatcher.CheckAccess())
            {
                Dispatcher.BeginInvoke((Action) delegate
                {
                    DoLyricsProgressReport(song, stage);
                });

                return;
            }

            ITrack track = controller.CurrentTrack;

            if (track?.GetHashCode() == song.GetHashCode())
            {
                if ((stage >= 0) && (stage <= 5))
                {
                    taskPanel.LyricsState = stage.ToString();
                }
                else
                {
                    taskPanel.LyricsState = string.Empty;
                }
            }
        }
示例#3
0
        /// <summary>
        /// BackgroundWorker RunWorkerCompleted method.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void LyricsRetrieved(object sender, RunWorkerCompletedEventArgs e)
        {
            if (e.Cancelled)
            {
                return;
            }

            if (e.Error != null)
            {
                // when the Preferences dialog is open, iTunes does not response to COM interops
                return;
            }

            ISong song = e.Result as ISong;

            if (song == null)
            {
                return;
            }

            var hash = song.GetHashCode();

            lock (engine)
            {
                // when iTunes forces a shutdown of iTuner, Dispose might have
                // run immediately prior to this lock, so we need to check for null
                if (queue != null)
                {
                    if (queue.ContainsKey(hash))
                    {
                        queue.Remove(hash);
                    }
                }
            }

            // signal regardless of whether lyrics is empty so we can update the UI
            LyricsUpdated?.Invoke(song as Track);
        }
示例#4
0
        //========================================================================================
        // Methods
        //========================================================================================
        /// <summary>
        /// Asynchronously searches for the lyrics of the given song.
        /// </summary>
        /// <param name="song">An ISong specifying both the artist and title of the song.</param>
        public void RetrieveLyrics(ISong song)
        {
            // song could be null if we called this method just when switching tracks
            // yes a very small window but nonetheless..
            if (!isConnected || (song == null))
            {
                return;
            }

            int hash = song.GetHashCode();

            lock (engine)
            {
                if (!queue.ContainsKey(hash))
                {
                    BackgroundWorker worker = new BackgroundWorker();
                    worker.DoWork += new DoWorkEventHandler(RetrieveLyrics);
                    worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(LyricsRetrieved);
                    worker.WorkerSupportsCancellation = true;

                    queue.Add(song.GetHashCode(), worker);

                    worker.RunWorkerAsync(song);
                }
            }
        }