private void GetSubscribers() { lock (Spotify.Mutex) { var subscribersPtr = Spotify.sp_playlist_subscribers(Handle); var subscribers = (Spotify.SpotifySubscribers)Marshal.PtrToStructure(subscribersPtr, typeof(Spotify.SpotifySubscribers)); _subscribers.Clear(); if (subscribers.Count > 0) { var arrayPtr = IntPtr.Add(subscribersPtr, sizeof(uint)); var arrayPtrs = new IntPtr[subscribers.Count]; Marshal.Copy(arrayPtr, arrayPtrs, 0, arrayPtrs.Length); for (int i = 0; i < arrayPtrs.Length; i++) { string userName = Spotify.GetString(arrayPtrs[i], string.Empty); if (!string.IsNullOrEmpty(userName)) { _subscribers.Add(userName); } } } Spotify.sp_playlist_subscribers_free(subscribersPtr); } }
public override string ToString() { if (IsInvalid) { return(string.Empty); } IntPtr bufferPtr = IntPtr.Zero; try { int size = Spotify.STRINGBUFFER_SIZE; bufferPtr = Marshal.AllocHGlobal(size); lock (Spotify.Mutex) { Spotify.sp_link_as_string(Handle, bufferPtr, size); } return(Spotify.GetString(bufferPtr, string.Empty)); } finally { try { Marshal.FreeHGlobal(bufferPtr); } catch { } } }
private void OnDescriptionChangedCallback(IntPtr playlistPtr, IntPtr descptr, IntPtr userdataptr) { if (playlistPtr != _playlist.Handle) { return; } string description = Spotify.GetString(descptr, string.Empty); _playlist.QueueThis(() => _playlist.OnDescriptionChanged(new DescriptionEventArgs(description))); }
private string GetFolderName() { IntPtr ptr = IntPtr.Zero; try { int index = _container.Playlists.IndexOf(this); int bufferSize = Spotify.STRINGBUFFER_SIZE; Error error; lock (Spotify.Mutex) { ptr = Marshal.AllocHGlobal(bufferSize); error = Spotify.sp_playlistcontainer_playlist_folder_name(_container.GetHandle(), index, ptr, bufferSize); } if (error == Error.OK) { return(Spotify.GetString(ptr, "Folder")); } return(error.GetMessage()); } catch { return("Folder"); } finally { if (ptr != IntPtr.Zero) { Marshal.FreeHGlobal(ptr); } } }