public void BrowsePlaylist(Playlist aPlaylist) { iPlaylistBrowse = aPlaylist; aPlaylist.AddCallbacks(iPlaylistListener, null); PlaylistBrowseTry(); }
public int CmdAddTrack(string[] aArgs) { List <Action> cleanup = new List <Action>(); try { if (aArgs.Length < 4) { Console.WriteLine("Usage: add <playlist-uri> <position> <track-uri> [<track-uri>...]"); return(1); } Link plink = Link.CreateFromString(aArgs[1]); if (plink == null) { Console.Error.WriteLine("{0} is not a spotify link", aArgs[1]); return(-1); } cleanup.Add(plink.Release); if (plink.Type() != LinkType.Playlist) { Console.Error.WriteLine("{0} is not a playlist link", aArgs[1]); return(-1); } Playlist playlist = Playlist.Create(iSession, plink); cleanup.Add(() => { if (playlist != null) { playlist.Release(); } }); int position; if (!int.TryParse(aArgs[2], out position) || position <0 || position> playlist.NumTracks()) { Console.Error.WriteLine("Position out of range"); } var tracks = CreateTracksFromLinks(aArgs.Skip(3)).ToArray(); var work = new UpdateWork { Index = position, Tracks = tracks }; if (ApplyChanges(playlist, work)) { return(1); } Console.Error.WriteLine("Playlist not yet loaded, waiting..."); playlist.AddCallbacks(iCallbacks, work); playlist = null; // Callback now owns the playlist. Don't release it in 'finally'. return(0); } finally { cleanup.Reverse(); foreach (var action in cleanup) { action(); } } }