Exemplo n.º 1
0
        // Loading files
        public async Task <bool> LoadFiles(IEnumerable <StorageFile> audioFiles, IEnumerable <StorageFile> imageFiles)
        {
            AlbumCover  cover;
            StorageFile imageFile = imageFiles.FirstOrDefault();

            if (imageFile != null)
            {
                cover = GetExistingAlbumCover(imageFile.Path);
                if (cover == null)
                {
                    cover = await AlbumCover.FromStorageFile(imageFile);

                    if (cover != null)
                    {
                        AlbumCovers.Add(cover);
                        string faToken = Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Add(imageFile);
                    }
                }
            }
            else
            {
                cover = null;
            }

            foreach (var file in audioFiles)
            {
                var item = await PlaylistItemStatic.LoadFromFile(file);

                Add(item);
                string faToken = Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList.Add(file);
                if (cover != null)
                {
                    item.MainCover = cover;
                }
            }
            if (Shuffle)
            {
                GenerateRandomIndexes();
            }

            if (Items.Count() > 0)
            {
                HasItems = true;
            }
            else
            {
                HasItems = false;
            }

            if (SelectedIndex == -1)
            {
                SelectedIndex = 0;
            }
            return(true);
        }
Exemplo n.º 2
0
        public static async Task <List <PlaylistItem> > RetrievePlaylistItemsByPlaylistId(int id)
        {
            using (SqliteConnection db = OnelyDB.Open())
            {
                SqliteCommand command = new SqliteCommand
                {
                    Connection  = db,
                    CommandText = "SELECT audio_path, cover_path FROM playlist_items WHERE playlist_id=@ID ORDER BY sort_order ASC"
                };
                command.Parameters.AddWithValue("@ID", id);
                var res = OnelyDB.ExecuteReader(command);

                if (!res.HasRows)
                {
                    return(null);
                }

                List <PlaylistItem> items  = new List <PlaylistItem>();
                List <AlbumCover>   covers = new List <AlbumCover>();

                while (res.Read())
                {
                    var item = await LoadFromPath(res.GetString(0));

                    if (item != null)
                    {
                        items.Add(item);
                        var coverPath = res.GetString(1);
                        if ((item.Cover == null) && (!String.IsNullOrEmpty(coverPath)))
                        {
                            AlbumCover cover = GetExistingAlbumCover(coverPath, covers);
                            if (cover == null)
                            {
                                cover = await AlbumCover.FromPath(coverPath);

                                if (cover != null)
                                {
                                    covers.Add(cover);
                                }
                            }
                            if (cover != null)
                            {
                                item.MainCover = cover;
                            }
                        }
                    }
                }
                covers.Clear();
                OnelyDB.Close(db);
                return(items);
            }
        }