private static void PlaylistMovedCallback(IntPtr containerPtr, IntPtr playlistPtr, int position, int new_position, IntPtr userDataPtr) { PlaylistContainer pc = GetContainer(containerPtr); if (pc != null) { Playlist pl; Playlist[] currentLists; lock (libspotify.Mutex) { // when moving a playlist "up", the indices are re-arranged so need to adjust the new_position // when moving a playlist "down" all is good... if (position < new_position) { new_position--; } pl = pc.playlists[position]; pc.playlists.RemoveAt(position); pc.playlists.Insert(new_position, pl); currentLists = pc.CurrentLists; } pc.owningSession.EnqueueEventWorkItem(new EventWorkItem(pc.OnPlaylistMoved, new object[] { pc, new PlaylistContainerEventArgs(pl, position, new_position, currentLists) })); } }
private static void PlaylistRemovedCallback(IntPtr containerPtr, IntPtr playlistPtr, int position, IntPtr userDataPtr) { PlaylistContainer pc = GetContainer(containerPtr); if (pc != null) { Playlist pl; Playlist[] currentLists; lock (libspotify.Mutex) { if (!pc.playlists[position].playlistPtr.Equals(playlistPtr)) { throw new Exception("libspotify-sharp internal error, playlist position and pointer is inconsistent on remove"); } pl = pc.playlists[position]; pc.playlists.RemoveAt(position); pc.playlistIndexByPtr.Remove(playlistPtr); pl.Dispose(); currentLists = pc.CurrentLists; } pc.owningSession.EnqueueEventWorkItem(new EventWorkItem(pc.OnPlaylistRemoved, new object[] { pc, new PlaylistContainerEventArgs(pl, position, -1, currentLists) })); } }
public IAsyncResult BeginLoadPlaylistContainer(AsyncCallback userCallback, object state) { IntPtr p = LibSpotify.sp_session_playlistcontainer_r(Handle); if (p == IntPtr.Zero) { return new AsyncLoadableResult <PlaylistContainer>( null, (container) => { return Error.Ok; }, userCallback, state) { CompletedSynchronously = true } } ; PlaylistContainer playlistContainer = new PlaylistContainer(p, false); return(AsyncLoadableResult <PlaylistContainer> .Begin( playlistContainer, (container) => { return Error.Ok; }, userCallback, state)); }
private static PlaylistContainer GetContainer(IntPtr containerPtr) { PlaylistContainer pc = null; if (containers.TryGetValue(containerPtr, out pc)) { return(pc); } else { return(null); } }
private static void ContainerLoadedCallback(IntPtr containerPtr, IntPtr userDataPtr) { PlaylistContainer pc = GetContainer(containerPtr); if (pc != null) { Playlist[] currentLists; lock (libspotify.Mutex) { currentLists = pc.CurrentLists; } // It's more practical to have this event on Session IMHO. Let's have both. pc.owningSession.EnqueueEventWorkItem(new EventWorkItem(pc.OnContainerLoaded, new object[] { pc, new PlaylistContainerEventArgs(null, -1, -1, currentLists) })); pc.owningSession.PlaylistContainerLoaded(); } }
private static void PlaylistAddedCallback(IntPtr containerPtr, IntPtr playlistPtr, int position, IntPtr userDataPtr) { PlaylistContainer pc = GetContainer(containerPtr); if (pc != null) { Playlist pl; Playlist[] currentLists; lock (libspotify.Mutex) { pl = new Playlist(playlistPtr, pc.owningSession); pc.playlists.Insert(position, pl); pc.playlistIndexByPtr[playlistPtr] = position; currentLists = pc.CurrentLists; } pc.owningSession.EnqueueEventWorkItem(new EventWorkItem(pc.OnPlaylistAdded, new object[] { pc, new PlaylistContainerEventArgs(pl, position, -1, currentLists) })); } }
void PlaylistContainer_OnContainerLoaded(PlaylistContainer sender, PlaylistContainerEventArgs e) { playlistLoaded = true; throw new NotImplementedException(); }