public static extern IntPtr sp_search_create( IntPtr sessionPtr, [MarshalAs(UnmanagedType.LPStr)]string query, int track_offset, int track_count, int album_offset, int album_count, int artist_offset, int artist_count, int playlist_offset, int playlist_count, sp_search_type search_type, search_complete_cb callback, IntPtr userDataPtr);
public static extern IntPtr sp_search_create( IntPtr sessionPtr, [MarshalAs(UnmanagedType.LPStr)] string query, int track_offset, int track_count, int album_offset, int album_count, int artist_offset, int artist_count, int playlist_offset, int playlist_count, sp_search_type search_type, search_complete_cb callback, IntPtr userDataPtr);
private void Search__Complete(IntPtr searchPtr, IntPtr userdataPtr) { if (searchPtr == this.searchPtr) { this.isComplete = true; session.EnqueueEventWorkItem(new EventWorkItem(CreateDelegate <SearchEventArgs>(s => s.OnComplete, this), new SearchEventArgs(this))); _Complete -= new search_complete_cb(Search__Complete); } }
private Search(Session session, IntPtr searchPtr) { if (searchPtr == IntPtr.Zero) { throw new ArgumentException("searchPtr can't be zero"); } if (session == null) { throw new ArgumentNullException("Session can't be null"); } this.session = session; this.searchPtr = searchPtr; this.tracks = new DelegateArray <ITrack>(() => { IsAlive(true); lock (libspotify.Mutex) return(libspotify.sp_search_num_tracks(searchPtr)); }, (index) => { IsAlive(true); lock (libspotify.Mutex) return(Track.Get(session, libspotify.sp_search_track(searchPtr, index))); }); this.albums = new DelegateArray <IAlbum>(() => { IsAlive(true); lock (libspotify.Mutex) return(libspotify.sp_search_num_albums(searchPtr)); }, (index) => { IsAlive(true); lock (libspotify.Mutex) return(Album.Get(session, libspotify.sp_search_album(searchPtr, index))); }); this.artists = new DelegateArray <IArtist>(() => { IsAlive(true); lock (libspotify.Mutex) return(libspotify.sp_search_num_artists(searchPtr)); }, (index) => { IsAlive(true); lock (libspotify.Mutex) return(Artist.Get(session, libspotify.sp_search_artist(searchPtr, index))); }); _Complete += new search_complete_cb(Search__Complete); session.DisposeAll += new SessionEventHandler(session_DisposeAll); }
protected override void OnDispose() { _Complete -= new search_complete_cb(Search__Complete); session.DisposeAll -= new SessionEventHandler(session_DisposeAll); if (!session.ProcExit) { lock (libspotify.Mutex) libspotify.sp_search_release(searchPtr); } searchPtr = IntPtr.Zero; }
private Search(Session session, IntPtr searchPtr) { if (searchPtr == IntPtr.Zero) { throw new ArgumentException("searchPtr can't be zero"); } if (session == null) { throw new ArgumentNullException("Session can't be null"); } this.session = session; this.searchPtr = searchPtr; this.tracks = new DelegateArray <ITrack>(() => { IsAlive(true); lock (libspotify.Mutex) return(libspotify.sp_search_num_tracks(searchPtr)); }, (index) => { IsAlive(true); lock (libspotify.Mutex) return(Track.Get(session, libspotify.sp_search_track(searchPtr, index))); }); this.albums = new DelegateArray <IAlbum>(() => { IsAlive(true); lock (libspotify.Mutex) return(libspotify.sp_search_num_albums(searchPtr)); }, (index) => { IsAlive(true); lock (libspotify.Mutex) return(Album.Get(session, libspotify.sp_search_album(searchPtr, index))); }); this.artists = new DelegateArray <IArtist>(() => { IsAlive(true); lock (libspotify.Mutex) return(libspotify.sp_search_num_artists(searchPtr)); }, (index) => { IsAlive(true); lock (libspotify.Mutex) return(Artist.Get(session, libspotify.sp_search_artist(searchPtr, index))); }); this.playlists = new DelegateArray <IPlaylist>(() => { IsAlive(true); lock (libspotify.Mutex) return(libspotify.sp_search_num_playlists(searchPtr)); }, (index) => { IsAlive(true); lock (libspotify.Mutex) { string playlistUri = libspotify.sp_search_playlist_uri(searchPtr, index); var playlistLink = session.ParseLink(playlistUri); if (playlistLink.Type == sp_linktype.SP_LINKTYPE_PLAYLIST) { var playlist = playlistLink.As <IPlaylist>(); playlistLink.Dispose(); return(playlist); } else { throw new Exception("Wrong link type: " + playlistLink.Type.ToString()); } } }); _Complete += new search_complete_cb(Search__Complete); session.DisposeAll += new SessionEventHandler(session_DisposeAll); }
public sp_error CreateSession() { if (ActiveSession()) throw new InvalidOperationException("There can only be one instance of the Spotify service."); _cacheLocation = "tmp"; _settingsLocation = "tmp"; IntPtr appKeyHandle = Marshal.AllocHGlobal(SpotifyAppKey.ApplicationKey.Length); Marshal.Copy(SpotifyAppKey.ApplicationKey, 0, appKeyHandle, SpotifyAppKey.ApplicationKey.Length); _notifyMainThreadCallback = NotifyMainThreadCallback; _loginCallback = LoginCallback; _searchCallback = SearchCallback; _sessionCallbacks.notify_main_thread = Marshal.GetFunctionPointerForDelegate(_notifyMainThreadCallback); _sessionCallbacks.connection_error = Marshal.GetFunctionPointerForDelegate(new connection_error(ConnectionErrorCallback)); _sessionCallbacks.logged_in = Marshal.GetFunctionPointerForDelegate(_loginCallback); IntPtr sessionCallbacksPtr = Marshal.AllocHGlobal(Marshal.SizeOf(_sessionCallbacks)); Marshal.StructureToPtr(_sessionCallbacks, sessionCallbacksPtr, true); _sessionConfig = new sp_session_config { api_version = SpotifyApiVersion, cache_location = _cacheLocation, settings_location = _cacheLocation, application_key = appKeyHandle, application_key_size = SpotifyAppKey.ApplicationKey.Length, user_agent = UserAgent, callbacks = sessionCallbacksPtr, userdata = IntPtr.Zero, compress_playlists = false, dont_save_metadata_for_playlists = true, initially_unload_playlists = true }; var error = sp_session_create(ref _sessionConfig, out _sessionHandle); if (error == sp_error.SP_ERROR_OK) Debug.WriteLine("Session successfully created."); else Debug.WriteLine("Session creation failed with error {0}", error); return error; }