protected override async Task EnsureHasDuration(MusicItem track) { var uri = await LocalLibrary.LocalUriIfExists(track); if (uri != null) { track.Duration = await StoreBeamPlayer.MediaElement.UriDuration(uri); } }
private async Task DownloadIfNecessary(MusicItem track) { var maybeLocalUri = await LocalLibrary.LocalUriIfExists(track); if (maybeLocalUri == null) { await BackgroundDownloader.DownloadAsync(track); } }
//private async Task<Uri> DownloadIfNotExists(MusicItem track, Func<Task<Uri>> performDownload) { // var maybeLocalUri = await LocalLibrary.LocalUriIfExists(track); // if(maybeLocalUri != null) { // return maybeLocalUri; // } // return await performDownload(); //} /// <summary> /// Prepares a download. A return value of null indicates that the download shall /// not proceed. This may be the case if the track already exists locally, or some /// IO error prevents the download, for example if the intended destination path /// is too long. /// </summary> /// <param name="track"></param> /// <returns>download parameters, or null if the track shall not be downloaded</returns> private async Task <DownloadParameters> GetDownloadInfo(MusicItem track) { var maybeLocalUri = await LocalLibrary.LocalUriIfExists(track); if (maybeLocalUri == null) { try { var source = RemoveCredentialsFromQueryParams(track.Source); var destFile = await Utils.FileTo(PathTo(track)); return(new DownloadParameters(source, destFile)); } catch (IOException) { // may have thrown PathTooLongException // does not proceed with the download return(null); } } else { return(null); } }