private async void SingerHotSongList_CurrentItemChanged(MediaPlaybackList sender, CurrentMediaPlaybackItemChangedEventArgs args) { uint CurrentIndex = sender.CurrentItemIndex; if (CurrentIndex == 4294967295) { return; } await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { if (MediaControl.MediaPlayer.Source == MediaPlayList.SingerHotSongList && MediaPlayList.HotSongBackup.Count > 0) { SearchSingleMusic music = MediaPlayList.HotSongBackup[Convert.ToInt32(CurrentIndex)]; var SongSearchResult = await NeteaseMusicAPI.GetInstance().SearchAsync <SingleMusicSearchResult>(music.MusicName, 5, 0, NeteaseMusicAPI.SearchType.Song); foreach (var Song in SongSearchResult.Result.Songs.Where(Song => Song.Name == music.MusicName && Song.Al.Name == music.Album).Select(Song => Song)) { var bitmap = new BitmapImage(); PicturePlaying.Source = bitmap; bitmap.UriSource = new Uri(Song.Al.PicUrl); break; } MediaItemDisplayProperties Props = args.NewItem.GetDisplayProperties(); Props.Type = Windows.Media.MediaPlaybackType.Music; Props.MusicProperties.Title = music.MusicName; Props.MusicProperties.Artist = music.Album; args.NewItem.ApplyDisplayProperties(Props); } }); }
private async void FontIcon_PointerPressed(object sender, PointerRoutedEventArgs e) { FontIcon FI = sender as FontIcon; SingleMusicControl.SelectedItem = ((FontIcon)sender).DataContext; SearchSingleMusic SSM = SingleMusicList[SingleMusicControl.SelectedIndex]; if (((SolidColorBrush)FI.Foreground).Color == Colors.White) { string MusicURL = (await NetEaseMusic.GetSongsUrlAsync(SingleMusicList[SingleMusicControl.SelectedIndex].SongID)).Data[0].Url; if (MusicURL == null) { ContentDialog dialog = new ContentDialog { Title = "抱歉", Content = "当前歌曲暂时无法播放", CloseButtonText = "确定", Background = Application.Current.Resources["DialogAcrylicBrush"] as Brush }; await dialog.ShowAsync(); return; } FI.Glyph = "\uEB52"; FI.Foreground = new SolidColorBrush(Colors.Red); MusicList.ThisPage.FavouriteMusicCollection.Add(new PlayList(SSM.MusicName, SSM.Artist, SSM.Album, SSM.Duration, SSM.ImageUrl, SSM.SongID[0], SSM.MVid)); MediaPlaybackItem Item = new MediaPlaybackItem(MediaSource.CreateFromUri(new Uri(MusicURL))); MediaItemDisplayProperties Props = Item.GetDisplayProperties(); Props.Type = Windows.Media.MediaPlaybackType.Music; Props.MusicProperties.Title = SSM.MusicName; Props.MusicProperties.Artist = SSM.Artist; Item.ApplyDisplayProperties(Props); MediaPlayList.FavouriteSongList.Items.Add(Item); await SQLite.GetInstance().SetMusicDataAsync(SSM.MusicName, SSM.Artist, SSM.Album, SSM.Duration, SSM.ImageUrl, SSM.SongID[0], SSM.MVid); } else { FI.Glyph = "\uEB51"; FI.Foreground = new SolidColorBrush(Colors.White); for (int i = 0; i < MusicList.ThisPage.FavouriteMusicCollection.Count; i++) { if (MusicList.ThisPage.FavouriteMusicCollection[i].SongID == SSM.SongID[0]) { await SQLite.GetInstance().DeleteMusicAsync(MusicList.ThisPage.FavouriteMusicCollection[i]); MusicList.ThisPage.FavouriteMusicCollection.RemoveAt(i); MediaPlayList.FavouriteSongList.Items.RemoveAt(i); break; } } } }
private async void AlbumSongList_CurrentItemChanged(MediaPlaybackList sender, CurrentMediaPlaybackItemChangedEventArgs args) { if (MediaPlayList.AlbumSongList.CurrentItemIndex == 4294967295) { return; } await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() => { BackBlurBrush.Amount = 0; BackBlurTicker.Start(); LrcControl.c_lrc_items.Children.Clear(); if (MusicPage.ThisPage.MediaControl.MediaPlayer.Source == MediaPlayList.AlbumSongList) { try { RollTicker.Start(); } catch (Exception) { } SearchSingleMusic PL = MediaPlayList.AlbumSongBackup[Convert.ToInt32(MediaPlayList.AlbumSongList.CurrentItemIndex)]; Title.Text = PL.MusicName; var SongSearchResult = await NetEaseMusic.SearchAsync <SingleMusicSearchResult>(PL.MusicName, 5, 0, NeteaseMusicAPI.SearchType.Song); foreach (var Song in SongSearchResult.Result.Songs.Where(Song => Song.Name == PL.MusicName && Song.Ar[0].Name == PL.Artist && Song.Al.Name == PL.Album).Select(Song => Song)) { var bitmap = new BitmapImage(); Image1.ImageSource = bitmap; bitmap.UriSource = new Uri(Song.Al.PicUrl); break; } GridBack.Background = new ImageBrush { ImageSource = Image1.ImageSource, Stretch = Stretch.UniformToFill }; LyricResult LrcTemp = await NetEaseMusic.GetLyricAsync(PL.SongID[0]); if (LrcTemp.Lrc == null) { TextBlock TB = new TextBlock() { Text = "纯音乐,无歌词", FontSize = 18 }; LrcControl.c_lrc_items.Children.Add(TB); RollTicker.Stop(); } else { LrcControl.LoadLrc(LrcTemp.Lrc.Lyric, LrcTemp.Tlyric.Lyric); } } else { try { RollTicker.Start(); } catch (Exception) { } var bitmap = new BitmapImage(); Image1.ImageSource = bitmap; bitmap.UriSource = new Uri(MusicSearch.ForDetail_ImageURL); GridBack.Background = new ImageBrush { ImageSource = Image1.ImageSource, Stretch = Stretch.UniformToFill }; Title.Text = MusicSearch.ForDetail_Name; LyricResult LrcTemp = await NetEaseMusic.GetLyricAsync(MusicSearch.ForDetail_ID); if (LrcTemp.Lrc == null) { TextBlock TB = new TextBlock() { Text = "纯音乐,无歌词", FontSize = 18 }; LrcControl.c_lrc_items.Children.Add(TB); RollTicker.Stop(); } else { LrcControl.LoadLrc(LrcTemp.Lrc.Lyric, LrcTemp.Tlyric.Lyric); } } }); }
private async void MusicDetail_Loaded(object sender, RoutedEventArgs e) { if (MusicPage.ThisPage.MediaControl.MediaPlayer.Source == MediaPlayList.FavouriteSongList) { PlayList PL = MusicList.ThisPage.FavouriteMusicCollection[Convert.ToInt32(MediaPlayList.FavouriteSongList.CurrentItemIndex)]; if (PL.SongID == LastSongID) { return; } else { LastSongID = PL.SongID; } LrcControl.c_lrc_items.Children.Clear(); Title.Text = PL.Music; var bitmap = new BitmapImage(); Image1.ImageSource = bitmap; bitmap.UriSource = new Uri(PL.ImageUrl); GridBack.Background = new ImageBrush { ImageSource = Image1.ImageSource, Stretch = Stretch.UniformToFill }; LyricResult LrcTemp = await NetEaseMusic.GetLyricAsync(PL.SongID); if (LrcTemp.Lrc == null) { TextBlock TB = new TextBlock() { Text = "纯音乐,无歌词", FontSize = 18 }; LrcControl.c_lrc_items.Children.Add(TB); RollTicker.Stop(); } else { LrcControl.LoadLrc(LrcTemp.Lrc.Lyric, LrcTemp.Tlyric?.Lyric); } } else if (MusicPage.ThisPage.MediaControl.MediaPlayer.Source == MediaPlayList.SingerHotSongList) { SearchSingleMusic PL = MediaPlayList.HotSongBackup[Convert.ToInt32(MediaPlayList.SingerHotSongList.CurrentItemIndex)]; if (PL.SongID[0] == LastSongID) { return; } else { LastSongID = PL.SongID[0]; } LrcControl.c_lrc_items.Children.Clear(); Title.Text = PL.MusicName; var SongSearchResult = await NetEaseMusic.SearchAsync <SingleMusicSearchResult>(PL.MusicName, 5, 0, NeteaseMusicAPI.SearchType.Song); foreach (var Song in SongSearchResult.Result.Songs.Where(Song => Song.Name == PL.MusicName && Song.Ar[0].Name == PL.Artist && Song.Al.Name == PL.Album).Select(Song => Song)) { var bitmap = new BitmapImage(); Image1.ImageSource = bitmap; bitmap.UriSource = new Uri(Song.Al.PicUrl); break; } GridBack.Background = new ImageBrush { ImageSource = Image1.ImageSource, Stretch = Stretch.UniformToFill }; LyricResult LrcTemp = await NetEaseMusic.GetLyricAsync(PL.SongID[0]); if (LrcTemp.Lrc == null) { TextBlock TB = new TextBlock() { Text = "纯音乐,无歌词", FontSize = 18 }; LrcControl.c_lrc_items.Children.Add(TB); RollTicker.Stop(); } else { LrcControl.LoadLrc(LrcTemp.Lrc.Lyric, LrcTemp.Tlyric?.Lyric); } } else if (MusicPage.ThisPage.MediaControl.MediaPlayer.Source == MediaPlayList.AlbumSongList) { SearchSingleMusic PL = MediaPlayList.AlbumSongBackup[Convert.ToInt32(MediaPlayList.AlbumSongList.CurrentItemIndex)]; if (PL.SongID[0] == LastSongID) { return; } else { LastSongID = PL.SongID[0]; } LrcControl.c_lrc_items.Children.Clear(); Title.Text = PL.MusicName; var SongSearchResult = await NetEaseMusic.SearchAsync <SingleMusicSearchResult>(PL.MusicName, 5, 0, NeteaseMusicAPI.SearchType.Song); foreach (var Song in SongSearchResult.Result.Songs.Where(Song => Song.Name == PL.MusicName && Song.Ar[0].Name == PL.Artist && Song.Al.Name == PL.Album).Select(Song => Song)) { var bitmap = new BitmapImage(); Image1.ImageSource = bitmap; bitmap.UriSource = new Uri(Song.Al.PicUrl); break; } GridBack.Background = new ImageBrush { ImageSource = Image1.ImageSource, Stretch = Stretch.UniformToFill }; LyricResult LrcTemp = await NetEaseMusic.GetLyricAsync(PL.SongID[0]); if (LrcTemp.Lrc == null) { TextBlock TB = new TextBlock() { Text = "纯音乐,无歌词", FontSize = 18 }; LrcControl.c_lrc_items.Children.Add(TB); RollTicker.Stop(); } else { LrcControl.LoadLrc(LrcTemp.Lrc.Lyric, LrcTemp.Tlyric?.Lyric); } } else { var bitmap = new BitmapImage(); Image1.ImageSource = bitmap; bitmap.UriSource = new Uri(MusicSearch.ForDetail_ImageURL); GridBack.Background = new ImageBrush { ImageSource = Image1.ImageSource, Stretch = Stretch.UniformToFill }; if (MusicSearch.ForDetail_ID == LastSongID) { return; } else { LastSongID = MusicSearch.ForDetail_ID; } LrcControl.c_lrc_items.Children.Clear(); Title.Text = MusicSearch.ForDetail_Name; LyricResult LrcTemp = await NetEaseMusic.GetLyricAsync(MusicSearch.ForDetail_ID); if (LrcTemp.Lrc == null) { TextBlock TB = new TextBlock() { Text = "纯音乐,无歌词", FontSize = 18 }; LrcControl.c_lrc_items.Children.Add(TB); RollTicker.Stop(); } else { LrcControl.LoadLrc(LrcTemp.Lrc.Lyric, LrcTemp.Tlyric?.Lyric); } }; }