/// <summary> /// Starts playback based on the preferred URI of the supplied track. /// /// Note that only remote or app-local URIs can directly be used as /// the Source of the underlying MediaElement. If the URI points to /// an non-app-local file path, we need to supply a FileStream as the /// MediaElement Source instead of a URI. /// /// The app furthermore needs to have been assigned permissions /// to access the local source of the track, if any. An exception /// is thrown if that is not the case. /// /// </summary> /// <param name="track">track to play</param> public async Task SetTrack(MusicItem track) { DisposeNullifyAndSuppress(sourceStream); // check local file availability latestTrack = track; var maybeLocalUri = await MultiFolderLibrary.Instance.LocalUriIfExists(track); Uri sourceUri = maybeLocalUri != null ? maybeLocalUri : track.Source; try { var file = await StoreFileUtils.GetFile(sourceUri); if (file != null) { // Bugfix: setting an ms-appdata URI directly to the Source when // the music source is remote sometimes throws an exception about Metadata, so we avoid that. // The identical ms-appdata URI seems to work if the music source is local. // The root cause is unresolved atm. await SetSource(file); } else { Player.Source = sourceUri; } } catch (FileNotFoundException) { // StoreFileUtils.GetFile throws FNFE if the file has special characters such as scandics (...) // even if it exists, so this is a bugfix for now Player.Source = track.Source; } // sets universal media control meta data MediaControl.TrackName = Utils.EmptyIfNull(track.Name); MediaControl.ArtistName = Utils.EmptyIfNull(track.Artist); }
public async Task <StorageFile> FileTo(string path) { var rootFolder = FileUtils.Folder; var destPath = StoreFileUtils.WindowsSeparators(path); // todo: Change ReplaceExisting to Fail, check existence before return(await rootFolder.CreateFileAsync(destPath, CreationCollisionOption.ReplaceExisting)); }
public StoreDownloader(StoreFileUtils fileUtils) { FileUtils = fileUtils; ActiveDownloads = new ObservableCollection <BindableDownloadOperation>(); Cts = new CancellationTokenSource(); CancelAllDownloads = new UnitCommand(CancelAll); ActiveDownloads.CollectionChanged += (s, e) => { OnPropertyChanged("IsDownloadsEmpty"); }; }
public static async Task <StorageFile> GetFile(MusicItem track) { var localUri = await MultiFolderLibrary.Instance.LocalUriIfExists(track); if (localUri == null) { return(null); } return(await StoreFileUtils.GetFile(localUri)); }
public async Task DownloadDiscoGsCover() { var service = StoreCoverService.Instance; var localCoverUri = await service.GetOrDownloadCover("Iron Maiden", "Powerslave"); Assert.IsNotNull(localCoverUri); StorageFile file = await StoreFileUtils.GetFile(localCoverUri); var size = await file.Size(); Assert.AreEqual(40407u, size); }
//public static Task<TimeSpan> StreamDuration(this MediaElement element, Stream stream) { // using(var stream = await file.OpenReadAsync()) { // return element.Duration(stream, (e, s) => e.SetSource(s, s.ContentType)); // } //} public static async Task <TimeSpan> UriDuration(this MediaElement element, Uri uri) { var file = await StoreFileUtils.GetFile(uri); if (file != null) { return(await element.FileDuration(file)); } else { return(await element.Duration(uri, (e, u) => e.Source = u)); } }
//public override Task<Stream> OpenStreamIfExists(MusicItem track) { // return FileUtil.OpenStreamIfExists(track.Path); //} public StoreFolderLocalLibrary(StorageFolder rootFolder) : base(rootFolder) { BaseMusicPath = ""; fileUtils = new StoreFileUtils(rootFolder); }
public StoreDownloader(StoreFileUtils fileUtils, string username, string password) : this(fileUtils) { }