Example #1
0
        internal string GetFolderName(ContainerPlaylist playlist)
        {
            int    index      = playlists.IndexOf(playlist);
            int    bufferSize = libspotify.STRINGBUFFER_SIZE;
            IntPtr bufferPtr  = IntPtr.Zero;

            try
            {
                bufferPtr = Marshal.AllocHGlobal(bufferSize);
                sp_error error;
                lock (libspotify.Mutex)
                    error = libspotify.sp_playlistcontainer_playlist_folder_name(pcPtr, index, bufferPtr, bufferSize);

                if (error == sp_error.OK)
                {
                    return(libspotify.GetString(bufferPtr, String.Empty));
                }
                else
                {
                    return(String.Empty);
                }
            }
            finally
            {
                if (bufferPtr != IntPtr.Zero)
                {
                    try { Marshal.FreeHGlobal(bufferPtr); }
                    catch { }
                }
            }
        }
Example #2
0
 internal static void Delete(IntPtr playlistPtr, IntPtr folderId, sp_playlist_type type)
 {
     lock (playlistsLock)
     {
         KeyGen            key      = new KeyGen(playlistPtr, folderId, type);
         ContainerPlaylist playlist = playlists[key];
         int count = playlist.RemRef();
         if (count == 0)
         {
             playlists.Remove(key);
         }
     }
 }
Example #3
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }
            if (obj.GetType() == typeof(Playlist))
            {
                return(base.Equals(obj));
            }
            if (obj.GetType() != typeof(ContainerPlaylist))
            {
                return(false);
            }
            ContainerPlaylist cp = (ContainerPlaylist)obj;

            return(cp.playlistPtr == this.playlistPtr && cp.folderId == this.folderId && this.type == cp.type);
        }
Example #4
0
        private PlaylistContainer(Session session, IntPtr pcPtr)
        {
            if (pcPtr == IntPtr.Zero)
            {
                throw new ArgumentException("pcPtr can't be zero");
            }

            if (session == null)
            {
                throw new ArgumentNullException("Session can't be null");
            }

            this.session = session;
            this.pcPtr   = pcPtr;

            this.playlist_added   = new playlist_added_cb(PlaylistAddedCallback);
            this.playlist_removed = new playlist_removed_cb(PlaylistRemovedCallback);
            this.playlist_moved   = new playlist_moved_cb(PlaylistMovedCallback);
            this.container_loaded = new container_loaded_cb(ContainerLoadedCallback);
            this.callbacks        = new sp_playlistcontainer_callbacks
            {
                playlist_added   = Marshal.GetFunctionPointerForDelegate(playlist_added),
                playlist_removed = Marshal.GetFunctionPointerForDelegate(playlist_removed),
                playlist_moved   = Marshal.GetFunctionPointerForDelegate(playlist_moved),
                container_loaded = Marshal.GetFunctionPointerForDelegate(container_loaded)
            };

            int size = Marshal.SizeOf(this.callbacks);

            this.callbacksPtr = Marshal.AllocHGlobal(size);
            Marshal.StructureToPtr(this.callbacks, this.callbacksPtr, true);

            lock (libspotify.Mutex)
            {
                libspotify.sp_playlistcontainer_add_callbacks(pcPtr, callbacksPtr, IntPtr.Zero);
            }

            session.DisposeAll += new SessionEventHandler(session_DisposeAll);

            playlists = new PlaylistList(
                () =>
            {
                IsAlive(true);
                lock (libspotify.Mutex)
                    return(libspotify.sp_playlistcontainer_num_playlists(pcPtr));
            },
                (index) =>
            {
                IsAlive(true);
                lock (libspotify.Mutex)
                    return(ContainerPlaylist.Get(session, this, libspotify.sp_playlistcontainer_playlist(pcPtr, index),
                                                 libspotify.sp_playlistcontainer_playlist_folder_id(pcPtr, index), libspotify.sp_playlistcontainer_playlist_type(pcPtr, index)));
            },
                (playlist, index) =>
            {
                IsAlive(true);
                IntPtr playlistPtr;
                int newIndex = 0;
                lock (libspotify.Mutex)
                {
                    playlistPtr = libspotify.sp_playlistcontainer_add_new_playlist(pcPtr, playlist.Name);
                    newIndex    = libspotify.sp_playlistcontainer_num_playlists(pcPtr);
                }
                if (playlistPtr != IntPtr.Zero)
                {
                    lock (libspotify.Mutex)
                        libspotify.sp_playlistcontainer_move_playlist(pcPtr, newIndex, index);
                }
            },
                (index) =>
            {
                IsAlive(true);
                lock (libspotify.Mutex)
                    libspotify.sp_playlistcontainer_remove_playlist(pcPtr, index);
            },
                () => false,
                (name) =>
            {
                IsAlive(true);
                IntPtr playlistPtr;
                int index;
                lock (libspotify.Mutex)
                {
                    playlistPtr = libspotify.sp_playlistcontainer_add_new_playlist(pcPtr, name);
                    index       = playlistPtr == IntPtr.Zero ? -1 : libspotify.sp_playlistcontainer_num_playlists(pcPtr) - 1;
                }
                return(index == -1 ? null : playlists[index]);
            }
                );
        }
Example #5
0
 protected override void OnDispose()
 {
     base.OnDispose();
     ContainerPlaylist.Delete(playlist.playlistPtr, ((ContainerPlaylist)playlist).folderId, ((ContainerPlaylist)playlist).type);
 }
Example #6
0
 public ContainerPlaylistWrapper(ContainerPlaylist playlist)
     : base(playlist)
 {
 }
 public ContainerPlaylistWrapper(ContainerPlaylist playlist)
     : base(playlist)
 {
 }