private IContainerPlaylist GetPlaylistAtIndex(int index)
 {
     lock (Spotify.Mutex)
     {
         return(ContainerPlaylistManager.Get(
                    Session,
                    this,
                    Spotify.sp_playlistcontainer_playlist(Handle, index),
                    Spotify.sp_playlistcontainer_playlist_folder_id(Handle, index),
                    Spotify.sp_playlistcontainer_playlist_type(Handle, index)));
     }
 }
        private IContainerPlaylist AddNewPlaylist(string name)
        {
            AssertHandle();

            lock (Spotify.Mutex)
            {
                IntPtr playlistPtr = Spotify.sp_playlistcontainer_add_new_playlist(Handle, name);

                return(ContainerPlaylistManager.Get(
                           Session,
                           this,
                           playlistPtr,
                           IntPtr.Zero,
                           PlaylistType.Playlist));
            }
        }
        private IContainerPlaylist AddExistingPlaylist(ILink <IPlaylist> link)
        {
            INativeObject nativeObject = (INativeObject)link;

            AssertHandle();

            lock (Spotify.Mutex)
            {
                IntPtr playlistPtr = Spotify.sp_playlistcontainer_add_playlist(Handle, nativeObject.Handle);

                return(ContainerPlaylistManager.Get(
                           Session,
                           this,
                           playlistPtr,
                           IntPtr.Zero,
                           PlaylistType.Playlist));
            }
        }
        private void OnPlaylistAddedCallback(IntPtr containerPointer, IntPtr playlistptr, int position, IntPtr userdataptr)
        {
            if (containerPointer != _container.Handle)
            {
                return;
            }

            var containerPlaylist = ContainerPlaylistManager.Get(
                _container.Session,
                _container,
                playlistptr,
                Spotify.sp_playlistcontainer_playlist_folder_id(containerPointer, position),
                Spotify.sp_playlistcontainer_playlist_type(containerPointer, position));

            var args = new PlaylistEventArgs(containerPlaylist, position);

            _container.QueueThis(() => _container.OnPlaylistAdded(args));
        }
        private void OnPlaylistMovedCallback(IntPtr containerPointer, IntPtr playlistptr, int position, int newposition, IntPtr userdataptr)
        {
            if (containerPointer != _container.Handle)
            {
                return;
            }

            // HACK : The indices are wrong when moving playlists up
            if (position < newposition)
            {
                newposition--;
            }

            var containerPlaylist = ContainerPlaylistManager.Get(
                _container.Session,
                _container,
                playlistptr,
                Spotify.sp_playlistcontainer_playlist_folder_id(containerPointer, position),
                Spotify.sp_playlistcontainer_playlist_type(containerPointer, position));

            var args = new PlaylistMovedEventArgs(containerPlaylist, position, newposition);

            _container.QueueThis(() => _container.OnPlaylistMoved(args));
        }
예제 #6
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                // Dispose managed
            }

            // Dispose unmanaged
            if (!IsInvalid)
            {
                try
                {
                    _mainThreadNotification.Set();

                    lock (_eventQueueLock)
                    {
                        Monitor.Pulse(_eventQueueLock);
                    }

                    if (_callbacks != null)
                    {
                        _callbacks.Dispose();
                        _callbacks = null;
                    }

                    PlaylistTrackManager.RemoveAll(this);
                    TrackManager.DisposeAll(this);

                    LinkManager.RemoveAll(this);
                    UserManager.RemoveAll(this);

                    PlaylistContainerManager.RemoveAll(this);
                    PlaylistManager.RemoveAll(this);
                    ContainerPlaylistManager.RemoveAll(this);
                    ArtistManager.RemoveAll();
                    AlbumManager.RemoveAll();

                    SessionManager.Remove(Handle);

                    lock (Spotify.Mutex)
                    {
                        Error error = Error.OK;

                        if (ConnectionState == ConnectionState.LoggedIn)
                        {
                            error = Spotify.sp_session_logout(Handle);
                            Debug.WriteLineIf(error != Error.OK, error.GetMessage());
                        }

                        error = Spotify.sp_session_release(Handle);
                        Debug.WriteLineIf(error != Error.OK, error.GetMessage());
                        Handle = IntPtr.Zero;
                    }
                }
                catch
                {
                    // Ignore
                }
                finally
                {
                    Debug.WriteLine("Session disposed");
                }
            }

            base.Dispose(disposing);
        }