protected override void OnDispose() { Artist.Delete(artist.artistPtr); artist = null; }
internal ArtistWrapper(Artist artist) { this.artist = artist; }
protected override void OnDispose() { Artist.Delete(artist.artistPtr); artist = null; }
public IEnumerable <ISpotifyObject> GetTopList(ToplistType listType, int maxNumber) { int currentRegion = -1; lock (libspotify.Mutex) { currentRegion = libspotify.sp_session_user_country(this.sessionPtr); } IntPtr topListBrowserPtr = IntPtr.Zero; ManualResetEvent reset = new ManualResetEvent(false); Exception createException = null; ThreadPool.QueueUserWorkItem(delegate(object obj) { try { lock (libspotify.Mutex) { topListBrowserPtr = libspotify.sp_toplistbrowse_create(this.sessionPtr, listType, currentRegion, null, GetPopularCallback, IntPtr.Zero); } } catch (Exception ex) { createException = ex; } finally { reset.Set(); } }); reset.WaitOne(); if (createException != null) { throw createException; } if (topListBrowserPtr == IntPtr.Zero) { throw new Exception("Top list browser pointer is zero"); } lock (popularLock) { if (!libspotify.sp_toplistbrowse_is_loaded(topListBrowserPtr)) { Monitor.Wait(popularLock); } } if (libspotify.sp_toplistbrowse_is_loaded(topListBrowserPtr)) { lock (libspotify.Mutex) { List <ISpotifyObject> objects = new List <ISpotifyObject>(); switch (listType) { case ToplistType.Tracks: { int maxTracks = libspotify.sp_toplistbrowse_num_tracks(topListBrowserPtr); if (maxTracks > maxNumber) { maxTracks = maxNumber; } for (int i = 0; i < maxTracks; i++) { var trackPtr = libspotify.sp_toplistbrowse_track(topListBrowserPtr, i); var track = Track.Get(this, trackPtr); objects.Add(track); } } break; case ToplistType.Artists: { int maxArtists = libspotify.sp_toplistbrowse_num_artists(topListBrowserPtr); if (maxArtists > maxNumber) { maxArtists = maxNumber; } for (int i = 0; i < maxArtists; i++) { var artistPtr = libspotify.sp_toplistbrowse_artist(topListBrowserPtr, i); var artist = Artist.Get(this, artistPtr); objects.Add(artist); } } break; case ToplistType.Albums: { int maxAlbums = libspotify.sp_toplistbrowse_num_albums(topListBrowserPtr); if (maxAlbums > maxNumber) { maxAlbums = maxNumber; } for (int i = 0; i < maxAlbums; i++) { var albumPtr = libspotify.sp_toplistbrowse_album(topListBrowserPtr, i); var album = Album.Get(this, albumPtr); objects.Add(album); } } break; default: throw new Exception("Unrecognized list type"); } libspotify.sp_toplistbrowse_release(topListBrowserPtr); return(objects); } } else { var error = libspotify.sp_toplistbrowse_error(topListBrowserPtr); libspotify.sp_toplistbrowse_release(topListBrowserPtr); throw new Exception("Error retrieving top list: " + error.ToString()); } }
internal ArtistWrapper(Artist artist) { this.artist = artist; }