How to create an array of Intptr?

May 16, 2013 at 9:34 AM
Edited May 16, 2013 at 9:35 AM
I would like to use the sp_playlist_add_tracks-function, but it seems like libspotify needs an array of tracks. Ho can I do that? I use the sp_link_as_track th get a track-intptr, but get INVALID_INDATA from Spotify.

For example:
IntPtr linkPtr = libspotifydotnet.libspotify.sp_link_create_from_string("spotify:track:78gsvivelCP8Kh0tSRTy8D");
IntPtr trackPtr = libspotifydotnet.libspotify.sp_link_as_track(linkPtr);    
libspotifydotnet.libspotify.sp_error error = libspotifydotnet.libspotify.sp_playlist_add_tracks(playlistPtr, trackPtr, 1, 0, sessionPtr);
Jun 23, 2013 at 9:42 PM
Don't know if you've solved your problem, but something like this should work:
       IntPtr tracksPtr = IntPtr.Zero;
        try
        {
            int[] array = new int[1];
            array[0] = trackPtr;

            int size = Marshal.SizeOf(tracksPtr) * array.Length;
            tracksPtr = Marshal.AllocHGlobal(size);
            Marshal.Copy(array, 0, tracksPtr, array.Length);

            var error = libspotify.sp_playlist_add_tracks(playlistPtr, tracksPtr, 1, 0, sessionPtr);
        }
        finally
        {
            if (tracksPtr != IntPtr.Zero)
            {
                Marshal.FreeHGlobal(tracksPtr);
            }

        }