public bool BeginBrowse() { this.IsLoaded = false; // set to false in case we're querying for a new page, the thread waits for true to know when things are done try { this.searchCompleteDelegate = new search_complete_cb_delegate(SearchCompleted); IntPtr callbackPtr = Marshal.GetFunctionPointerForDelegate(searchCompleteDelegate); switch (this.Type) { case SearchType.Track: _browsePtr = libspotify.sp_search_create(Session.GetSessionPtr(), this.Query, trackOffset, numResults, 0, 0, 0, 0, 0, 0, sp_search_type.SP_SEARCH_STANDARD, callbackPtr, IntPtr.Zero); break; case SearchType.Artist: _browsePtr = libspotify.sp_search_create(Session.GetSessionPtr(), this.Query, 0, 0, 0, 0, artistOffset, numResults, 0, 0, sp_search_type.SP_SEARCH_STANDARD, callbackPtr, IntPtr.Zero); break; case SearchType.Album: _browsePtr = libspotify.sp_search_create(Session.GetSessionPtr(), this.Query, 0, 0, albumOffset, numResults, 0, 0, 0, 0, sp_search_type.SP_SEARCH_STANDARD, callbackPtr, IntPtr.Zero); break; default: throw new InvalidOperationException("No search type set"); } return(true); } catch (Exception ex) { Logger.WriteDebug("Search.BeginBrowse() failed: {0}", ex.Message); return(false); } }
private Session(byte[] applicationKey, string cacheLocation, string settingsLocation, string userAgent) { libspotify.sp_session_config config = new libspotify.sp_session_config(); config.api_version = libspotify.SPOTIFY_API_VERSION; config.cache_location = cacheLocation; config.settings_location = settingsLocation; config.user_agent = userAgent; int size = Marshal.SizeOf(callbacks); config.callbacks = Marshal.AllocHGlobal(size); Marshal.StructureToPtr(callbacks, config.callbacks, true); config.application_key = IntPtr.Zero; try { config.application_key = Marshal.AllocHGlobal(applicationKey.Length); Marshal.Copy(applicationKey, 0, config.application_key, applicationKey.Length); lock (libspotify.Mutex) config.application_key_size = applicationKey.Length; sessionPtr = IntPtr.Zero; sp_error res = libspotify.sp_session_init(ref config, out sessionPtr); if (res != sp_error.OK) { throw new SpotifyException(res); } albumbrowse_complete_cb = new albumbrowse_complete_cb_delegate(AlbumBrowseCompleteCallback); artistbrowse_complete_cb = new artistbrowse_complete_cb_delegate(ArtistBrowseCompleteCallback); search_complete_cb = new search_complete_cb_delegate(SearchCompleteCallback); image_loaded_cb = new image_loaded_cb_delegate(ImageLoadedCallback); mainThread = new Thread(new ThreadStart(MainThread)); mainThread.IsBackground = true; mainThread.Start(); eventThread = new Thread(new ThreadStart(EventThread)); eventThread.IsBackground = true; eventThread.Start(); } finally { if (config.application_key != IntPtr.Zero) { Marshal.FreeHGlobal(config.application_key); } } }
private Session(byte[] applicationKey, string cacheLocation, string settingsLocation, string userAgent) { libspotify.sp_session_config config = new libspotify.sp_session_config(); config.api_version = libspotify.SPOTIFY_API_VERSION; config.cache_location = cacheLocation; config.settings_location = settingsLocation; config.user_agent = userAgent; int size = Marshal.SizeOf(callbacks); config.callbacks = Marshal.AllocHGlobal(size); Marshal.StructureToPtr(callbacks, config.callbacks, true); config.application_key = IntPtr.Zero; try { config.application_key = Marshal.AllocHGlobal(applicationKey.Length); Marshal.Copy(applicationKey, 0, config.application_key, applicationKey.Length); lock(libspotify.Mutex) config.application_key_size = applicationKey.Length; sessionPtr = IntPtr.Zero; sp_error res = libspotify.sp_session_init(ref config, out sessionPtr); if(res != sp_error.OK) { throw new SpotifyException(res); } albumbrowse_complete_cb = new albumbrowse_complete_cb_delegate(AlbumBrowseCompleteCallback); artistbrowse_complete_cb = new artistbrowse_complete_cb_delegate(ArtistBrowseCompleteCallback); search_complete_cb = new search_complete_cb_delegate(SearchCompleteCallback); image_loaded_cb = new image_loaded_cb_delegate(ImageLoadedCallback); mainThread = new Thread(new ThreadStart(MainThread)); mainThread.IsBackground = true; mainThread.Start(); eventThread = new Thread(new ThreadStart(EventThread)); eventThread.IsBackground = true; eventThread.Start(); } finally { if(config.application_key != IntPtr.Zero) { Marshal.FreeHGlobal(config.application_key); } } }