Ejemplo n.º 1
0
        private void UpdateNowPlaying(Task<NowPlaying> task)
        {
            switch (task.Status)
            {
                case TaskStatus.RanToCompletion:
                    Dispatcher.Invoke(() =>
                    {
                        foreach (NowPlayingEntry entry in task.Result.Entry)
                        {
                            string fileName = GetMusicFilename(entry);

                            NowPlayingItem nowPlayingItem = new NowPlayingItem
                            {
                                BitRate = entry.BitRate,
                                DiscNumber = entry.DiscNumber,
                                Duration = TimeSpan.FromSeconds(entry.Duration),
                                Genre = entry.Genre,
                                TrackNumber = entry.Track,
                                Rating = entry.UserRating,
                                Year = entry.Year,
                                Album = entry.Album,
                                Artist = entry.Artist,
                                Child = entry,
                                Starred = (entry.Starred != default(DateTime)),
                                Title = entry.Title,
                                User = entry.Username,
                                AlbumArtSize = _albumArtSize,
                                Cached = IsTrackCached(fileName, entry),
                                FileName = fileName,
                                When = (DateTime.Now - TimeSpan.FromMinutes(entry.MinutesAgo)).ToShortTimeString()
                            };

                            if (_nowPlayingItems.Any(a => a.Album == nowPlayingItem.Album && a.Artist == nowPlayingItem.Artist && a.Starred == nowPlayingItem.Starred && a.Title == nowPlayingItem.Title)) continue;

                            //NowPlayingStatusLabel.Content = string.Format("{0} is playing {1} by {2}", nowPlayingItem.User, nowPlayingItem.Title, nowPlayingItem.Artist);
                            _nowPlayingItems.Add(nowPlayingItem);

                            if (!_showAlbumArt) continue;

                            string localFileName = GetCoverArtFilename(entry);

                            if (File.Exists(localFileName))
                            {
                                Image thisImage = Image.FromFile(localFileName);
                                nowPlayingItem.Image = thisImage.ToBitmapSource().Resize(BitmapScalingMode.HighQuality, true, (int) (_albumArtSize * ScalingFactor), (int) (_albumArtSize * ScalingFactor));
                                thisImage.Dispose();
                            }
                            else
                            {
                                SubsonicClient.GetCoverArtAsync(entry.CoverArt).ContinueWith(t => UpdateNowPlayingAlbumImageArt(t, nowPlayingItem));
                            }
                        }
                    });
                    break;
            }
        }
Ejemplo n.º 2
0
 public App()
 {
     this.InitializeComponent();
     this.Suspending += OnSuspending;
     // Init the now playing item
     PlayingMedia = new NowPlayingItem();
     // Init the windows 8 mini player
     MediaControl.PlayPressed            += MediaControl_PlayPressed;
     MediaControl.PausePressed           += MediaControl_PausePressed;
     MediaControl.StopPressed            += MediaControl_StopPressed;
     MediaControl.PlayPauseTogglePressed += MediaControl_PlayPauseTogglePressed;
 }
Ejemplo n.º 3
0
        private void UpdateNowPlayingAlbumImageArt(Task<IImageFormat<Image>> task, NowPlayingItem nowPlayingItem)
        {
            switch (task.Status)
            {
                case TaskStatus.RanToCompletion:
                    Dispatcher.Invoke(() =>
                    {
                        Image coverArtImage = task.Result.GetImage();

                        if (coverArtImage == null) return;

                        string localFileName = GetCoverArtFilename(nowPlayingItem.Child);
                        coverArtImage.Save(localFileName);

                        nowPlayingItem.Image = coverArtImage.ToBitmapSource().Resize(BitmapScalingMode.HighQuality, true, (int)(_albumArtSize * ScalingFactor), (int)(_albumArtSize * ScalingFactor));
                    });
                    break;
            }
        }