public static async void downloadPlaylist(Playlist plist) { var songCount = plist.Songlist.Count; int songsFinished = 0; foreach (Song s in plist.Songlist) { if (!s.isDownloaded) { var i = plist.Songlist.IndexOf(s); await downloadSong(s, null); var songTmp = ((Song)plist.Songlist.Where(song => song.SongURL == s.SongURL)); songTmp.isDownloaded = true; songTmp.isDownloading = false; songTmp.downloadPath = (await DataIO.readSettings()).downloadPath; plist.Songlist.RemoveAt(i); plist.Songlist.Insert(i, songTmp); await DataIO.SavePlaylist(plist); } songsFinished++; plist.DownloadProgress = songsFinished / songCount; } }
public async void Play() { if (currentSong == null && currentPlaylist == null) { return; } if (currentPlaylist != null && currentSong == null) { this.currentSong = currentPlaylist.Songlist.FirstOrDefault(); } if (currentSong.isDownloaded) { try { StorageFolder sf = await StorageFolder.GetFolderFromPathAsync(currentSong.downloadPath); var storageFile = await sf.GetFileAsync(currentSong.DownloadTitle + ".mp3"); this.mPlayer.Source = MediaSource.CreateFromStorageFile(storageFile); this.mPlayer.Play(); } catch (FileNotFoundException) { Helper.ErrorDialog("Song not found!", "File was probably deleted. Please download it again."); var i = currentPlaylist.Songlist.IndexOf(currentSong); currentSong.isDownloaded = false; currentPlaylist.Songlist.RemoveAt(i); currentPlaylist.Songlist.Insert(i, currentSong); await DataIO.SavePlaylist(currentPlaylist); skipSong(); //TODO: update UI return; } } else { //if (!Helper.checkIfOnline()) // return; try { var stream = await this.GetAudioStream(currentSong.SongURL); this.mPlayer.Source = MediaSource.CreateFromUri(new Uri(stream)); this.mPlayer.Play(); } catch (System.Net.Http.HttpRequestException) { return; } catch (NullReferenceException) { //happens if "video" is not playable for some reason Helper.ErrorDialog("Cant Play this Song", "For some reason this song can't be played."); skipSong(); return; } } Helper.executeInUiThread(() => { this.StartLogoStackPanel.Visibility = Windows.UI.Xaml.Visibility.Collapsed; this.currPlayingRect.Fill = new ImageBrush { ImageSource = Helper.base64toBmp(currentSong.Thumbnail) }; this.currPlayingLabel.Text = currentSong.Title; }); this.smtc.IsNextEnabled = true; this.smtc.IsPlayEnabled = true; this.smtc.IsPauseEnabled = true; this.smtc.IsPreviousEnabled = true; this.smtc.DisplayUpdater.Thumbnail = RandomAccessStreamReference.CreateFromStream(await Helper.base64toStream(currentSong.Thumbnail)); this.smtc.DisplayUpdater.Update(); }