Beispiel #1
0
 public static Inbox PostTracks(
     SpotifySession session,
     string username,
     Track[] tracks,
     string message,
     InboxPostComplete callback,
     object userdata)
 {
     using (var utf8_username = SpotifyMarshalling.StringToUtf8(username))
         using (var utf8_message = SpotifyMarshalling.StringToUtf8(message))
             using (var track_array = SpotifyMarshalling.ArrayToNativeArray(tracks.Select(x => x._handle).ToArray()))
             {
                 IntPtr listenerToken = ListenerTable.PutUniqueObject(callback, userdata);
                 IntPtr ptr           = NativeMethods.sp_inbox_post_tracks(
                     session._handle,
                     utf8_username.IntPtr,
                     track_array.IntPtr,
                     track_array.Length,
                     utf8_message.IntPtr,
                     InboxPostCompleteDelegate,
                     listenerToken);
                 Inbox search = InboxTable.GetUniqueObject(ptr);
                 search.ListenerToken = listenerToken;
                 return(search);
             }
 }
Beispiel #2
0
        public string[] Subscribers()
        {
            IntPtr subscribers = NativeMethods.sp_playlist_subscribers(this._handle);

            string[] retval = SpotifyMarshalling.SubscribersToStrings(subscribers);
            var      error  = NativeMethods.sp_playlist_subscribers_free(subscribers);

            SpotifyMarshalling.CheckError(error);
            return(retval);
        }
Beispiel #3
0
 public static TopListBrowse Create(SpotifySession session, TopListType type, TopListRegion region, string username, TopListBrowseComplete callback, object userdata)
 {
     using (var utf8_username = SpotifyMarshalling.StringToUtf8(username))
     {
         IntPtr        listenerToken = ListenerTable.PutUniqueObject(callback, userdata);
         IntPtr        ptr           = NativeMethods.sp_toplistbrowse_create(session._handle, type, region, utf8_username.IntPtr, TopListBrowseCompleteDelegate, listenerToken);
         TopListBrowse browse        = BrowseTable.GetUniqueObject(ptr);
         browse.ListenerToken = listenerToken;
         return(browse);
     }
 }
Beispiel #4
0
        public void Dispose()
        {
            if (_handle == IntPtr.Zero)
            {
                return;
            }
            var error = NativeMethods.sp_search_release(_handle);

            SearchTable.ReleaseObject(_handle);
            ListenerTable.ReleaseObject(ListenerToken);
            _handle = IntPtr.Zero;
            SpotifyMarshalling.CheckError(error);
        }
        public void Dispose()
        {
            if (_handle == IntPtr.Zero)
            {
                return;
            }
            var error = NativeMethods.sp_session_release(_handle);

            SessionTable.ReleaseObject(_handle);
            ListenerTable.ReleaseObject(ListenerToken);
            NativeCallbackAllocation.ReleaseRef();
            _handle = IntPtr.Zero;
            SpotifyMarshalling.CheckError(error);
        }
Beispiel #6
0
 public static Search Create(
     SpotifySession session,
     string query,
     int trackOffset,
     int trackCount,
     int albumOffset,
     int albumCount,
     int artistOffset,
     int artistCount,
     int playlistOffset,
     int playlistCount,
     SearchType searchType,
     SearchComplete callback,
     object userdata)
 {
     using (var utf8_query = SpotifyMarshalling.StringToUtf8(query))
     {
         IntPtr listenerToken = ListenerTable.PutUniqueObject(callback, userdata);
         IntPtr ptr           = NativeMethods.sp_search_create(
             session._handle,
             utf8_query.IntPtr,
             trackOffset,
             trackCount,
             albumOffset,
             albumCount,
             artistOffset,
             artistCount,
             playlistOffset,
             playlistCount,
             searchType,
             SearchCompleteDelegate,
             listenerToken);
         Search search = SearchTable.GetUniqueObject(ptr);
         search.ListenerToken = listenerToken;
         return(search);
     }
 }
        static void CredentialsBlobUpdated(IntPtr @session, IntPtr @blob)
        {
            var context = GetListener(session);

            context.Listener.CredentialsBlobUpdated(context.Session, SpotifyMarshalling.Utf8ToString(blob));
        }
        static void LogMessage(IntPtr @session, IntPtr @data)
        {
            var context = GetListener(session);

            context.Listener.LogMessage(context.Session, SpotifyMarshalling.Utf8ToString(data));
        }
        static void MessageToUser(IntPtr @session, IntPtr @message)
        {
            var context = GetListener(session);

            context.Listener.MessageToUser(context.Session, SpotifyMarshalling.Utf8ToString(message));
        }
        /// <summary>
        /// Create a SpotifySession, as per sp_session_create.
        /// </summary>
        /// <param name="config"></param>
        /// <returns>
        /// The SpotifySession. The caller is responsible for calling Dispose on
        /// the session.
        /// </returns>
        public static SpotifySession Create(SpotifySessionConfig config)
        {
            IntPtr sessionPtr = IntPtr.Zero;
            IntPtr listenerToken;

            using (var cacheLocation = SpotifyMarshalling.StringToUtf8(config.CacheLocation))
                using (var settingsLocation = SpotifyMarshalling.StringToUtf8(config.SettingsLocation))
                    using (var userAgent = SpotifyMarshalling.StringToUtf8(config.UserAgent))
                        using (var deviceId = SpotifyMarshalling.StringToUtf8(config.DeviceId))
                            using (var proxy = SpotifyMarshalling.StringToUtf8(config.Proxy))
                                using (var proxyUsername = SpotifyMarshalling.StringToUtf8(config.ProxyUsername))
                                    using (var proxyPassword = SpotifyMarshalling.StringToUtf8(config.ProxyPassword))
#if SYSTEM_LINUX
                                        // The field is Linux-only.
                                        using (var caCertsFilename = SpotifyMarshalling.StringToUtf8(config.CACertsFilename))
#endif
                                        using (var traceFile = SpotifyMarshalling.StringToUtf8(config.TraceFile))
                                        {
                                            IntPtr appKeyPtr = IntPtr.Zero;
                                            listenerToken = ListenerTable.PutUniqueObject(config.Listener, config.UserData);
                                            try
                                            {
                                                NativeCallbackAllocation.AddRef();
                                                byte[] appkey = config.ApplicationKey;
                                                appKeyPtr = Marshal.AllocHGlobal(appkey.Length);
                                                Marshal.Copy(config.ApplicationKey, 0, appKeyPtr, appkey.Length);
                                                sp_session_config nativeConfig = new sp_session_config {
                                                    api_version                      = config.ApiVersion,
                                                    cache_location                   = cacheLocation.IntPtr,
                                                    settings_location                = settingsLocation.IntPtr,
                                                    application_key                  = appKeyPtr,
                                                    application_key_size             = (UIntPtr)appkey.Length,
                                                    user_agent                       = userAgent.IntPtr,
                                                    callbacks                        = SessionDelegates.CallbacksPtr,
                                                    userdata                         = listenerToken,
                                                    compress_playlists               = config.CompressPlaylists,
                                                    dont_save_metadata_for_playlists = config.DontSaveMetadataForPlaylists,
                                                    initially_unload_playlists       = config.InitiallyUnloadPlaylists,
                                                    device_id                        = deviceId.IntPtr,
                                                    proxy          = proxy.IntPtr,
                                                    proxy_username = proxyUsername.IntPtr,
                                                    proxy_password = proxyPassword.IntPtr,
#if SYSTEM_LINUX
                                                    // The ca_certs_filename field is Linux-only.
                                                    ca_certs_filename = caCertsFilename.IntPtr,
#endif
                                                    tracefile = traceFile.IntPtr,
                                                };
                                                // Note: sp_session_create will invoke a callback, so it's important that
                                                // we have already done ListenerTable.PutUniqueObject before this point.
                                                var error = NativeMethods.sp_session_create(ref nativeConfig, ref sessionPtr);
                                                SpotifyMarshalling.CheckError(error);
                                            }
                                            catch
                                            {
                                                ListenerTable.ReleaseObject(listenerToken);
                                                NativeCallbackAllocation.ReleaseRef();
                                                throw;
                                            }
                                            finally
                                            {
                                                if (appKeyPtr != IntPtr.Zero)
                                                {
                                                    Marshal.FreeHGlobal(appKeyPtr);
                                                }
                                            }
                                        }

            SpotifySession session = SessionTable.GetUniqueObject(sessionPtr);

            session.Listener      = config.Listener;
            session.UserData      = config.UserData;
            session.ListenerToken = listenerToken;
            return(session);
        }
Beispiel #11
0
 public static string ErrorMessage(SpotifyError error)
 {
     return(SpotifyMarshalling.Utf8ToString(NativeMethods.sp_error_message(error)));
 }
Beispiel #12
0
 public static string BuildId()
 {
     return(SpotifyMarshalling.Utf8ToString(NativeMethods.sp_build_id()));
 }
Beispiel #13
0
        static void track_message_changed(IntPtr @pl, int @position, IntPtr @message, IntPtr @userdata)
        {
            var context = GetListener(pl, userdata);

            context.Listener.TrackMessageChanged(context.Playlist, position, SpotifyMarshalling.Utf8ToString(message), context.Userdata);
        }
Beispiel #14
0
        static void description_changed(IntPtr @pl, IntPtr @desc, IntPtr @userdata)
        {
            var context = GetListener(pl, userdata);

            context.Listener.DescriptionChanged(context.Playlist, SpotifyMarshalling.Utf8ToString(desc), context.Userdata);
        }
Beispiel #15
0
        static void tracks_moved(IntPtr @pl, IntPtr @tracks, int @num_tracks, int @new_position, IntPtr @userdata)
        {
            var context = GetListener(pl, userdata);

            context.Listener.TracksMoved(context.Playlist, SpotifyMarshalling.NativeIntArrayToArray(tracks, num_tracks), new_position, context.Userdata);
        }
Beispiel #16
0
        static void tracks_added(IntPtr @pl, IntPtr @tracks, int @num_tracks, int @position, IntPtr @userdata)
        {
            var context = GetListener(pl, userdata);

            context.Listener.TracksAdded(context.Playlist, SpotifyMarshalling.NativeHandleArrayToArray(tracks, num_tracks).Select(x => new Track(x)).ToArray(), position, context.Userdata);
        }