public static async Task SaveSingleFileAlbumArtAsync(Mediafile mp3file, StorageFile file = null) { if (mp3file != null) { try { if (file == null) file = await StorageFile.GetFileFromPathAsync(mp3file.Path); var albumartFolder = ApplicationData.Current.LocalFolder; var albumartLocation = albumartFolder.Path + @"\AlbumArts\" + (mp3file.Album + mp3file.LeadArtist).ToLower().ToSha1() + ".jpg"; StorageItemThumbnail thumbnail = await file.GetThumbnailAsync(ThumbnailMode.MusicView).AsTask().ConfigureAwait(false); if (!VerifyFileExists(albumartLocation, 300) && thumbnail != null && thumbnail.Type == ThumbnailType.Image) { await LibVM.SaveImages(thumbnail, mp3file).ConfigureAwait(false); mp3file.AttachedPicture = albumartLocation; } } catch { await NotificationManager.ShowAsync("Failed to save album art of " + mp3file.OrginalFilename); } } }
async void ImportPlaylists() { var picker = new FileOpenPicker(); FileOpenPicker openPicker = new FileOpenPicker(); openPicker.ViewMode = PickerViewMode.Thumbnail; openPicker.SuggestedStartLocation = PickerLocationId.MusicLibrary; openPicker.FileTypeFilter.Add(".m3u"); openPicker.FileTypeFilter.Add(".pls"); StorageFile file = await openPicker.PickSingleFileAsync(); IPlaylist playlist = null; if (Path.GetExtension(file.Path) == ".m3u") { playlist = new M3U(); } else { playlist = new PLS(); } var dict = await playlist.LoadPlaylist(file); LibVM.AddPlaylist(dict, file.DisplayName, ""); }
async void Reset() { LibVM.Dispose(); await Player.Stop(); ShellVM.Dispose(); AlbumArtistVM.Dispose(); LibraryFoldersCollection.Clear(); await ApplicationData.Current.ClearAsync(); LibVM.Database = new Database.DatabaseQueryMethods(); AlbumArtistVM.InitDB(); // GC.Collect(); LibVM.SongCount = 0; ResetCommand.IsEnabled = false; await Task.Delay(200); ResetCommand.IsEnabled = true; }
async void ImportPlaylists() { var picker = new FileOpenPicker(); FileOpenPicker openPicker = new FileOpenPicker(); openPicker.ViewMode = PickerViewMode.Thumbnail; openPicker.SuggestedStartLocation = PickerLocationId.MusicLibrary; openPicker.FileTypeFilter.Add(".m3u"); openPicker.FileTypeFilter.Add(".pls"); StorageFile file = await openPicker.PickSingleFileAsync(); if(file != null) { var plist = new Playlist() { Name = file.DisplayName }; LibVM.AddPlaylist(plist); LibVM.Database.playlists.Insert(plist); IPlaylist playlist = null; if (Path.GetExtension(file.Path) == ".m3u") playlist = new M3U(); else playlist = new PLS(); await playlist.LoadPlaylist(file).ConfigureAwait(false); } }