public sealed partial class MainPage : Page { public static readonly string[] audioExtensions = new string[] { ".wma", ".mp3", ".mp2", ".aac", ".adt", ".adts", ".m4a" }; public static readonly string[] playlistExtensions = new string[] { ".m3u", ".wpl", ".zpl" }; Playlist playlist = new Playlist(); public MainPage() { this.InitializeComponent(); } async private void Page_Loaded(object sender, RoutedEventArgs e) { try { playlist = await PickPlaylistAsync(); if (playlist != null) { foreach (StorageFile file in playlist.Files) { MusicProperties properties = await file.Properties.GetMusicPropertiesAsync(); lstPlaylist.Items.Add(properties.Title); } } } catch (Exception) { throw; } } async private void btnAdd_Click(object sender, RoutedEventArgs e) { try { FileOpenPicker picker = CreateFilePicker(audioExtensions); IReadOnlyList<StorageFile> files = await picker.PickMultipleFilesAsync(); if (files != null && files.Count > 0) { foreach (StorageFile file in files) { playlist.Files.Add(file); } await playlist.SaveAsync(); } } catch (Exception) { throw; } } async public static Task<Playlist> PickPlaylistAsync() { FileOpenPicker picker = CreateFilePicker(playlistExtensions); StorageFile file = await picker.PickSingleFileAsync(); Playlist playlist = null; if (file != null) { return await Playlist.LoadAsync(file); } return playlist; } public static FileOpenPicker CreateFilePicker(string[] extensions) { FileOpenPicker picker = new FileOpenPicker(); picker.SuggestedStartLocation = PickerLocationId.MusicLibrary; foreach (string extension in extensions) { picker.FileTypeFilter.Add(extension); } return picker; } async private void btnSave_Click(object sender, RoutedEventArgs e) { try { if (PlaylistName.Text != "") { StorageFile savedFile = await playlist.SaveAsAsync(KnownFolders.MusicLibrary, PlaylistName.Text, NameCollisionOption.ReplaceExisting, PlaylistFormat.WindowsMedia); } else { } } catch (Exception) { throw; } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)