internal async Task <IList <Song> > GetSongsAsync()
        {
            var albums = await FileReader.GetAlbumsAsync(RawName);

            var songs = new List <Song>();

            albums.ForEach(async x =>
            {
                var m = new AlbumViewModel(x);
                songs.AddRange(await m.GetSongsAsync());
            });
            return(songs);
        }
        public async Task GetSongsAsync(AlbumViewModel a)
        {
            Album = a;
            await a.GetSongsAsync();

            await CoreApplication.MainView.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
            {
                SongList.Clear();
                for (int i = 0; i < a.Songs.Count; i++)
                {
                    SongList.Add(new SongViewModel(a.Songs[i])
                    {
                        Index = (uint)i
                    });
                }
                foreach (var item in SongList)
                {
                    item.RefreshFav();
                }
            });

            var info = await MainPageViewModel.Current.GetAlbumInfoAsync(Album.Name, Album.AlbumArtists.FirstOrDefault());

            await CoreApplication.MainView.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
            {
                if (info != null)
                {
                    if (Album.Artwork == null && info.AltArtwork != null)
                    {
                        Album.ArtworkUri = info.AltArtwork;
                        var task         = ThreadPool.RunAsync(async k =>
                        {
                            if (!Album.IsOnline)
                            {
                                await SQLOperator.Current().UpdateAlbumArtworkAsync(album.ID, info.AltArtwork.OriginalString);
                            }
                        });
                    }
                    Album.Description = info.Description;
                }
                else
                {
                    Album.Description = $"# {Consts.Localizer.GetString("LocaAlbumTitle")}";
                }
            });
        }
示例#3
0
        internal async Task PlayAlbumAsync(AlbumViewModel album)
        {
            var songs = await album.GetSongsAsync();

            await MainPageViewModel.Current.InstantPlayAsync(songs);
        }
        public async Task GetSongsAsync(AlbumViewModel a)
        {
            Album = a;
            await a.GetSongsAsync();

            await CoreApplication.MainView.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
            {
                SongList.Clear();

                var songViewmodels = new List <SongViewModel>();

                for (int i = 0; i < a.Songs.Count; i++)
                {
                    songViewmodels.Add(new SongViewModel(a.Songs[i])
                    {
                        Index = (uint)i
                    });
                }

                var group = GroupedItem <SongViewModel> .CreateGroups(songViewmodels, s => s.Disc);

                foreach (var item in group)
                {
                    var ordered = item.OrderBy(s => s.Track).ToList();
                    item.Clear();
                    foreach (var o in ordered)
                    {
                        item.Add(o);
                    }
                    SongList.Add(item);
                }

                Task.Run(async() =>
                {
                    var favors = await SQLOperator.Current().GetFavoriteAsync();
                    await CoreApplication.MainView.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
                    {
                        foreach (var disc in SongList)
                        {
                            foreach (var song in disc)
                            {
                                if (favors.Contains(song.ID))
                                {
                                    if (favors.Count == 0)
                                    {
                                        return;
                                    }
                                    song.Favorite = true;
                                    favors.Remove(song.ID);
                                }
                            }
                        }
                    });
                });
            });

            AlbumInfo info = null;

            try
            {
                if (Album.Name != null)
                {
                    info = await MainPageViewModel.Current.GetAlbumInfoAsync(Album.Name, Album.AlbumArtists?.FirstOrDefault());
                }
            }
            catch (Exception)
            {
            }
            await CoreApplication.MainView.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
            {
                if (info != null)
                {
                    if (Album.ArtworkUri == null && info.AltArtwork != null)
                    {
                        Album.ArtworkUri = info.AltArtwork;
                        var task         = ThreadPool.RunAsync(async k =>
                        {
                            if (!Album.IsOnline)
                            {
                                await SQLOperator.Current().UpdateAlbumArtworkAsync(album.ID, info.AltArtwork.OriginalString);
                            }
                        });
                    }
                    Album.Description = info.Description;
                }
                else
                {
                    Album.Description = $"# {Consts.Localizer.GetString("LocaAlbumTitle")}";
                }
            });
        }