Exemple #1
0
        private async void Player_StatusChanged(object sender, PlayingItemsChangedArgs e)
        {
            await CoreApplication.MainView.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, async() =>
            {
                IsPlaying = player.IsPlaying;
                if (e.CurrentSong != null)
                {
                    if (!_lastSong.IsIDEqual(e.CurrentSong))
                    {
                        Song = new SongViewModel(e.CurrentSong);

                        CurrentRating = Song.Rating;

                        SongChanged?.Invoke(Song, EventArgs.Empty);

                        if (Song.Artwork != null)
                        {
                            if (lastUriPath == Song.Artwork.AbsolutePath)
                            {
                            }
                            else
                            {
                                CurrentArtwork    = Song.Artwork;
                                CurrentColorBrush = new SolidColorBrush(await ImagingHelper.GetMainColor(CurrentArtwork));
                                MainPageViewModel.Current.LeftTopColor = AdjustColorbyTheme(CurrentColorBrush);
                                lastUriPath = Song.Artwork.AbsolutePath;
                            }
                        }
                        else
                        {
                            CurrentArtwork    = null;
                            CurrentColorBrush = new SolidColorBrush(new UISettings().GetColorValue(UIColorType.Accent));
                            MainPageViewModel.Current.LeftTopColor = AdjustColorbyTheme(CurrentColorBrush);
                            lastUriPath = null;
                        }
                        if (e.Items is IList <Song> l)
                        {
                            NowListPreview = $"{e.CurrentIndex + 1}/{l.Count}";
                            NowPlayingList.Clear();
                            for (int i = 0; i < l.Count; i++)
                            {
                                NowPlayingList.Add(new SongViewModel(l[i])
                                {
                                    Index = (uint)i
                                });
                            }
                            if (e.CurrentIndex < NowPlayingList.Count)
                            {
                                CurrentIndex = e.CurrentIndex;
                            }
                        }

                        IsCurrentFavorite = await e.CurrentSong.GetFavoriteAsync();
                    }
                }
            });

            if (e.CurrentSong != null)
            {
                if (!_lastSong.IsIDEqual(e.CurrentSong))
                {
                    await CoreApplication.MainView.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
                    {
                        Lyric.Clear();
                        LyricHint = Consts.Localizer.GetString("LoadingLyricsText");
                    });

                    _lastSong = e.CurrentSong;
                    var ext = MainPageViewModel.Current.LyricExtension;
                    if (ext != null)
                    {
                        var result = await ext.ExecuteAsync(new ValueSet()
                        {
                            new KeyValuePair <string, object>("q", "lyric"),
                            new KeyValuePair <string, object>("title", Song.Title),
                            new KeyValuePair <string, object>("album", song.Album),
                            new KeyValuePair <string, object>("artist", Song.Song.Performers.IsNullorEmpty() ? null : Song.Song.Performers[0]),
                            new KeyValuePair <string, object>("ID", song.IsOnline ? song.Song.OnlineID : null)
                        });

                        if (result != null)
                        {
                            var l = new Lyric(LrcParser.Parser.Parse((string)result, Song.Song.Duration));
                            await CoreApplication.MainView.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
                            {
                                Lyric.New(l);
                            });
                        }
                        else
                        {
                            await CoreApplication.MainView.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
                            {
                                Lyric.Clear();
                                LyricHint = Consts.Localizer.GetString("NoLyricText");
                            });
                        }
                    }
                    else
                    {
                        await CoreApplication.MainView.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
                        {
                            Lyric.Clear();
                            LyricHint = Consts.Localizer.GetString("NoLyricText");
                        });
                    }
                }
            }
        }
Exemple #2
0
        public async void Init(SongViewModel song)
        {
            //Initialize our picker object
            castingPicker = new CastingDevicePicker();

            //Set the picker to filter to video capable casting devices
            castingPicker.Filter.SupportsAudio = true;

            //Hook up device selected event
            castingPicker.CastingDeviceSelected += CastingPicker_CastingDeviceSelected;

            Song      = song;
            _lastSong = new Song()
            {
                ID            = song.ID,
                IsOnline      = song.IsOnline,
                OnlineUri     = new Uri(song.FilePath),
                FilePath      = song.FilePath,
                Duration      = song.Song.Duration,
                Album         = song.Album,
                OnlineAlbumID = song.Song.OnlineAlbumID,
                OnlineID      = song.Song.OnlineID
            };
            CurrentArtwork = song.Artwork;
            lastUriPath    = song.Artwork?.AbsolutePath;
            IsPlaying      = player.IsPlaying;
            BufferProgress = MainPageViewModel.Current.BufferProgress;
            SongChanged?.Invoke(song, EventArgs.Empty);
            CurrentRating = song.Rating;
            var brush = new SolidColorBrush(await ImagingHelper.GetMainColor(CurrentArtwork));

            CurrentColorBrush = brush;
            MainPageViewModel.Current.LeftTopColor = AdjustColorbyTheme(CurrentColorBrush);
            CurrentIndex = MainPageViewModel.Current.CurrentIndex;
            var task = ThreadPool.RunAsync(async x =>
            {
                var favor = await _lastSong.GetFavoriteAsync();
                await CoreApplication.MainView.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
                {
                    IsCurrentFavorite = favor;
                });
            });

            var t = ThreadPool.RunAsync(async x =>
            {
                var ext = MainPageViewModel.Current.LyricExtension;
                if (ext != null)
                {
                    var result = await ext.ExecuteAsync(new ValueSet()
                    {
                        new KeyValuePair <string, object>("q", "lyric"),
                        new KeyValuePair <string, object>("title", Song.Title),
                        new KeyValuePair <string, object>("album", song.Album),
                        new KeyValuePair <string, object>("artist", Song.Song.Performers.IsNullorEmpty() ? null : Song.Song.Performers[0]),
                        new KeyValuePair <string, object>("ID", song.IsOnline ? song.Song.OnlineID : null)
                    });
                    if (result != null)
                    {
                        var l = new Lyric(LrcParser.Parser.Parse((string)result, Song.Song.Duration));
                        await CoreApplication.MainView.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Low, () =>
                        {
                            Lyric.New(l);
                        });
                    }
                    else
                    {
                        await CoreApplication.MainView.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Low, () =>
                        {
                            Lyric.Clear();
                            LyricHint = Consts.Localizer.GetString("NoLyricText");
                        });
                    }
                }
                else
                {
                    await CoreApplication.MainView.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Low, () =>
                    {
                        Lyric.Clear();
                        LyricHint = Consts.Localizer.GetString("NoLyricText");
                    });
                }
            });
        }