public async Task Download(SongListItem obj) { SmuleClient client = new SmuleClient(); if (Device.RuntimePlatform == Device.Android) { DependencyService.Get <ISaveFile>().SaveFile(); //string thePath = Environment..GetExternalStoragePublicDirectory(Environment.DirectoryDocuments).AbsolutePath Environment.GetFolderPath(Environment.SpecialFolder.); await client.DownloadSong(obj.DownloadUri, obj.Title, "/storage/emulated/0/Music/"); } if (Device.RuntimePlatform == Device.iOS) { string downloadPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); downloadPath = Path.Combine(downloadPath, "Music"); if (!Directory.Exists(downloadPath)) { Directory.CreateDirectory(downloadPath); } //ToDo //There is some trouble with file.exists // if(!File.Exists(Path.Combine(downloadPath,obj.Title + ".mp4"))) var progress = new Progress <float>(); progress.ProgressChanged += Download_Progress_Changed; await client.DownloadSong(obj.DownloadUri, ReplaceIllegal(obj.Title, "_") + "_" + ReplaceIllegal(obj.Performare, "_"), downloadPath, obj.progress); } }
GetFavorites() { SmuleClient client = new SmuleClient(); IsBusy = true; List <SmuleLib.Model.List> favSongs = await client.GetFavoritesAsync(userName, _count); IsBusy = false; if (Device.RuntimePlatform == Device.iOS) { string downloadPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); downloadPath = Path.Combine(downloadPath, "Music"); Random rnd = new Random(); foreach (SmuleLib.Model.List song in favSongs) { SongListItem item = new SongListItem(); item.Title = song.title; item.Performare = song.other_performers.Length > 0 ? (song.other_performers[0].handle + " - " + song.owner.handle) : song.owner.handle; item.PerformanceDate = song.created_at.ToString(); item.PerformareGroup = song.owner.handle; item.DownloadUri = song.web_url; item.Progress = rnd.Next(0, 100); string path = Path.Combine(downloadPath, ReplaceIllegal(item.Title, "_") + "_" + ReplaceIllegal(item.Performare, "_") + ".mp4"); if (!item.IsDownloaded && File.Exists(path)) { System.IO.FileInfo fi = new FileInfo(path); if (fi.Length > 500000) { item.IsDownloaded = true; } else { fi.Delete(); } } userList.Add(item); } } }