public Task TrackToFileAsync(Track track, string filename, CancellationTokenSource cts) { _filename = filename; _track = track; _cts = cts; // _track = new Track(trackLink, this); // track.Album.BeginBrowse(); // while (!track.Album.IsBrowseComplete) if (!track.IsLoaded) Thread.Sleep(1000); var status = LoadPlayer(track); if (status == libspotify.sp_error.OK) { this.Reset(); Play(); return Task.Run(() => { while (!_completed) { Thread.Sleep(10); } }, cts.Token); // libspotify.sp_link_release(trackPtr); // libspotify.sp_link_release(linkPtr); } else { return null; } }
public static void Main(string[] args) { using (_downloadSession = new DownloadSession(key, "Spoti")) { #region login login: Console.Write("Username:"******"Password:"******"Login Failed. Try again.."); goto login; } Console.WriteLine("Login Succeeded"); #endregion Console.Write("Track Url:"); var turl = Console.ReadLine(); var link = new Link(turl, _downloadSession); int t = -1; _downloadSession.OnReportProgress += delegate(int i) { if (i != t) { Console.Title = String.Format("{0}% Loaded", i); t = i; } }; var cts = new CancellationTokenSource(); using (var track = new Track(link, _downloadSession)) { link.Dispose(); var task = _downloadSession.TrackToFileAsync(track, "test.wave", cts); Console.WriteLine("Press enter to terminate .. "); Console.Read(); } _downloadSession.LogOut(); Console.Read(); } }
private void _AlbumbrowseComplete(IntPtr result, IntPtr userDataPtr) { try { libspotify.sp_error error = libspotify.sp_albumbrowse_error(result); if (error != libspotify.sp_error.OK) { _session.Log.Error(ModuleId, String.Format("Album browse failed: {0}", libspotify.sp_error_message(error))); return; } if (Tracks == null) Tracks = new List<Track>(); else { if (Tracks != null) foreach (var track in Tracks) track.Dispose(); Tracks.Clear(); } int numtracks = libspotify.sp_albumbrowse_num_tracks(_browsePtr); for (int i = 0; i < libspotify.sp_albumbrowse_num_tracks(_browsePtr); i++) { var trackPtr = libspotify.sp_albumbrowse_track(_browsePtr, i); var track = new Track(trackPtr, _session); Tracks.Add(track); } this.IsBrowseComplete = true; } finally { EndBrowse(); } }