Example #1
0
        public void PollAndUpdate()
        {
            // Find background image (if any)
            string skinDir = System.IO.Path.Combine(Directory.GetCurrentDirectory(), "Skin");

            string[] backgroundImages = Directory.GetFiles(@skinDir, "background.*");

            TrackInfo lastPlayed = null;

            while (!StopAlready)
            {
                TrackInfo nowPlaying = nowPlayingProvider.WhatIsNowPlaying();
                if (nowPlaying != null)
                {
                    if (!nowPlaying.Equals(lastPlayed) || (lastPlayed.AlbumArtUrl == null))
                    {
                        ViewModel model = new ViewModel();

                        // Fetching the Cover may take some time, so do it first
                        FileInfo coverFile = coverManager.GetCover(nowPlaying);
                        if (coverFile != null)
                        {
                            model.CoverImage = coverFile.FullName;
                        }
                        model.Artist = nowPlaying.Artist;
                        model.Title  = nowPlaying.Title;
                        if (backgroundImages.Length > 0)
                        {
                            model.BackgroundImage = backgroundImages[0];
                        }

                        dispatcher.Invoke(DispatcherPriority.Render, new Action(() => RefreshWindow(model)));
                        lastPlayed = nowPlaying;
                    }
                }
                else
                {
                    // Reset model
                    ViewModel model = new ViewModel();

                    FileInfo coverFile = coverManager.GetDefaultCover();
                    if (coverFile != null)
                    {
                        model.CoverImage = coverFile.FullName;
                    }
                    if (backgroundImages.Length > 0)
                    {
                        model.BackgroundImage = backgroundImages[0];
                    }

                    dispatcher.Invoke(DispatcherPriority.Render, new Action(() => RefreshWindow(model)));
                    lastPlayed = null;
                }

                Thread.Sleep(5000);
            }
        }