async void Open(object para) { var picker = new FileOpenPicker(); FileOpenPicker openPicker = new FileOpenPicker(); openPicker.ViewMode = PickerViewMode.Thumbnail; openPicker.SuggestedStartLocation = PickerLocationId.MusicLibrary; openPicker.FileTypeFilter.Add(".mp3"); openPicker.FileTypeFilter.Add(".wav"); openPicker.FileTypeFilter.Add(".ogg"); openPicker.FileTypeFilter.Add(".flac"); openPicker.FileTypeFilter.Add(".m4a"); openPicker.FileTypeFilter.Add(".aif"); openPicker.FileTypeFilter.Add(".wma"); StorageFile file = await openPicker.PickSingleFileAsync(); if (file != null) { var mp3file = await CoreMethods.CreateMediafile(file); if (Player.PlayerState == PlayerState.Paused || Player.PlayerState == PlayerState.Stopped) { Load(mp3file); } else { Load(mp3file, true); } } }
public async static Task AddStorageFilesToLibrary(StorageFileQueryResult queryResult) { foreach (var file in await queryResult.GetFilesAsync()) { Mediafile mp3file = null; int index = -1; if (file != null) { if (LibVM.TracksCollection.Elements.Any(t => t.Path == file.Path)) { index = LibVM.TracksCollection.Elements.IndexOf(LibVM.TracksCollection.Elements.First(t => t.Path == file.Path)); RemoveMediafile(LibVM.TracksCollection.Elements.First(t => t.Path == file.Path)); } //this methods notifies the Player that one song is loaded. We use both 'count' and 'i' variable here to report current progress. await NotificationManager.ShowAsync(" Song(s) Loaded", "Loading..."); await Task.Run(async () => { //here we load into 'mp3file' variable our processed Song. This is a long process, loading all the properties and the album art. mp3file = await CoreMethods.CreateMediafile(file, false); //the core of the whole method. await SaveSingleFileAlbumArtAsync(mp3file, file).ConfigureAwait(false); }); AddMediafile(mp3file, index); } } }
/// <summary> /// Loads songs from a specified folder into the library. <seealso cref="LoadCommand"/> /// </summary> public async void Load() { FolderPicker picker = new FolderPicker() { SuggestedStartLocation = PickerLocationId.MusicLibrary }; CoreMethods Methods = new CoreMethods(); picker.FileTypeFilter.Add(".mp3"); StorageFolder folder = await picker.PickSingleFolderAsync(); if (folder != null) { var filelist = Macalifa.Common.DirectoryWalker.GetFiles(folder.Path); LibraryFoldersCollection.Add(folder); foreach (var x in filelist) { StorageFile file = await StorageFile.GetFileFromPathAsync(x); LibraryViewModel.Path = file.Path; using (var stream = await LibVM.Dispatcher.RunTaskAsync(LibraryViewModel.GetFileAsStream)) { if (stream != null) { var path = file.Path; if (LibVM.TracksCollection.Elements.All(t => t.Path != path)) { var m = await Methods.CreateMediafile(stream); LibVM.TracksCollection.AddItem(m); LibVM.db.Insert(m); } } } } } }
/// <summary> /// Loads songs from a specified folder into the library. <seealso cref="LoadCommand"/> /// </summary> public async void Load() { FolderPicker picker = new FolderPicker() { SuggestedStartLocation = PickerLocationId.MusicLibrary }; CoreMethods Methods = new CoreMethods(); picker.FileTypeFilter.Add(".mp3"); StorageFolder folder = await picker.PickSingleFolderAsync(); LibraryFoldersCollection.Add(folder); if (folder != null) { if (StorageApplicationPermissions.FutureAccessList.Entries.Count <= 999) { StorageApplicationPermissions.FutureAccessList.Clear(); } StorageApplicationPermissions.FutureAccessList.Add(folder); var filelist = await BreadPlayer.Common.DirectoryWalker.GetFiles(folder.Path); //folder.GetFilesAsync(Windows.Storage.Search.CommonFileQuery.OrderByName); // var tempList = new List <Mediafile>(); DispatcherTimer timer = new DispatcherTimer(); timer.Interval = TimeSpan.FromSeconds(2); timer.Start(); var stop = System.Diagnostics.Stopwatch.StartNew(); double i = 0; var count = filelist.Count(); foreach (var x in filelist) { i++; double percent = (i / count) * 100; await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { LibVM.Progress = percent; }); Mediafile mp3file = null; StorageFile file = await StorageFile.GetFileFromPathAsync(x); string path = file.Path; if (LibVM.TracksCollection.Elements.All(t => t.Path != path)) { try { mp3file = await CoreMethods.CreateMediafile(file); tempList.Add(mp3file); } catch { } timer.Tick += (sender, e) => { LibVM.TracksCollection.AddRange(tempList); LibVM.db.Insert(tempList); tempList.Clear(); }; } } AlbumArtistVM.AddAlbums(); stop.Stop(); ShowMessage(stop.ElapsedMilliseconds.ToString() + " " + LibVM.TracksCollection.Elements.Count.ToString()); } }