private async void Player_StatusChanged(object sender, PlayingItemsChangedArgs e) { await CoreApplication.MainView.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, async() => { if (e.CurrentIndex == -1) { //CurrentSong = null; //NowPlayingList.Clear(); //NowListPreview = "-/-"; //CurrentTitle = null; //CurrentAlbum = null; //CurrentArtist = null; //await CurrentArtwork.SetSourceAsync(await RandomAccessStreamReference.CreateFromUri(new Uri(Consts.BlackPlaceholder)).OpenReadAsync()); //CurrentIndex = -1; //NeedShowPanel = false; //IsPodcast = false; //ReleaseDisplay(); return; } if (e.CurrentSong != null) { CurrentSong = e.CurrentSong; //CurrentSong.IsPlaying = true; //var p = e.CurrentSong; ////CurrentTitle = p.Title.IsNullorEmpty() ? p.FilePath.Split('\\').LastOrDefault() : p.Title; ////IsPodcast = p.IsPodcast; ////CurrentAlbum = p.Album.IsNullorEmpty() ? Consts.UnknownAlbum : p.Album; ////CurrentArtist = p.Performers == null ? (p.AlbumArtists == null ? Consts.UnknownArtists : string.Join(Consts.CommaSeparator, p.AlbumArtists)) : string.Join(Consts.CommaSeparator, p.Performers); //if (e.Thumnail != null) //{ // await CurrentArtwork.SetSourceAsync(await e.Thumnail.OpenReadAsync()); //} //else //{ // var thumb = RandomAccessStreamReference.CreateFromUri(new Uri(Consts.BlackPlaceholder)); // await CurrentArtwork.SetSourceAsync(await thumb.OpenReadAsync()); //} if (EnableTile) { var task = Task.Run(() => { Tile.ShowTileNotification(CurrentSong.Name, CurrentSong.Artist, CurrentSong.AlbumImage, CurrentPlayVol.Vol.VolNum, CurrentPlayVol.Vol.Title, CurrentPlayVol.Vol.Cover); }); } //if (e.Items is IReadOnlyList<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, // }); // } //} CurrentSongIndex = e.CurrentIndex; // ApplicationView.GetForCurrentView().Title = CurrentPlayingDesc(); // if (e.CurrentSong != null && Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.UI.Shell.AdaptiveCardBuilder")) // { // var last = NowPlayingList.Count - 1 <= currentIndex; // string img0, img1; // img1 = null; // if (!NowPlayingList[currentIndex].IsOnline) // { // //if (NowPlayingList[currentIndex].Song.PicturePath.IsNullorEmpty()) // //{ // // img0 = Consts.BlackPlaceholder; // //} // //else // //{ // // img0 = $"ms-appdata:///temp/{NowPlayingList[currentIndex].Artwork.AbsoluteUri.Split('/').Last()}"; // //} // img0 = null; // } // else // { // img0 = NowPlayingList[currentIndex].Artwork?.AbsoluteUri; // } // var otherArtwork = NowPlayingList.Where(a => a.Artwork?.AbsoluteUri != img0); // foreach (var item in otherArtwork) // { // if (!item.IsOnline) // { // img1 = null; // } // else // { // img1 = item.Artwork.AbsoluteUri; // } // break; // } // var json = await TimelineCard.AuthorAsync(currentTitle, currentAlbum, currentArtist, img0, img1, NowPlayingList.Count); // act.ActivationUri = new Uri("as-music:///?action=timeline-restore"); // act.VisualElements.Content = AdaptiveCardBuilder.CreateAdaptiveCardFromJson(json); // act.VisualElements.DisplayText = Consts.Localizer.GetString("AppNameText"); // act.VisualElements.Description = Consts.Localizer.GetString("TimelineTitle"); // await act.SaveAsync(); // var songs = NowPlayingList.Where(s => s.IsOnedrive || s.IsOnline).Select(s => s.Song).ToList(); //#pragma warning disable CS4014 // 由于此调用不会等待,因此在调用完成前将继续执行当前方法 // Task.Run(async () => // { // if (songs.Count > 0) // { // var status = new PlayerStatus(songs, currentIndex, currentPosition); // await status.RoamingSaveAsync(); // } // else // { // await PlayerStatus.ClearRoamingAsync(); // } // }); //#pragma warning restore CS4014 // 由于此调用不会等待,因此在调用完成前将继续执行当前方法 // await CoreApplication.MainView.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => // { // try // { // //Dispose of any current UserActivitySession, and create a new one. // (_currentActivity as UserActivitySession)?.Dispose(); // _currentActivity = act.CreateSession(); // } // catch (Exception) // { // } // }); // } if (e.CurrentSong != null && Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.UI.Shell.AdaptiveCardBuilder")) { try { if (EnableTimeline) { CreatVolPlayTimelineAsync(CurrentPlayVol); } } catch (Exception) { } } } }); }
private async void Player_StatusChanged(object sender, PlayingItemsChangedArgs e) { await CoreApplication.MainView.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () => { IsPlaying = player.IsPlaying; if (e.CurrentIndex == -1) { NowPlayingList.Clear(); NowListPreview = "-/-"; CurrentTitle = null; CurrentAlbum = null; CurrentArtwork = null; lastUriPath = null; CurrentIndex = -1; NeedShowPanel = false; return; } if (e.CurrentSong != null) { var p = e.CurrentSong; CurrentTitle = p.Title.IsNullorEmpty() ? p.FilePath.Split('\\').LastOrDefault() : p.Title; CurrentAlbum = p.Album.IsNullorEmpty() ? (p.Performers.IsNullorEmpty() ? Consts.UnknownAlbum : string.Join(Consts.CommaSeparator, p.Performers)) : p.Album; if (!p.PicturePath.IsNullorEmpty()) { if (lastUriPath == p.PicturePath) { } else { CurrentArtwork = new Uri(p.PicturePath); lastUriPath = p.PicturePath; } } else { CurrentArtwork = null; } Task.Run(() => { Tile.SendNormal(CurrentTitle, CurrentAlbum, string.Join(Consts.CommaSeparator, p.Performers ?? new string[] { }), p.PicturePath); }); } 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; } if (MainPage.Current.IsCurrentDouban) { return; } else { NeedShowPanel = true; } }); }
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"); }); } } } }