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 void beginLoad() { _d = new image_loaded_cb_delegate(onImageLoaded); _callbackPtr = Marshal.GetFunctionPointerForDelegate(_d); var err = libspotify.sp_image_add_load_callback(this.ImagePtr, _callbackPtr, IntPtr.Zero); if (err != libspotify.sp_error.OK) { throw new ApplicationException("Unable to add image load callbacks"); } }
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 void beginLoad() { _d = new image_loaded_cb_delegate(onImageLoaded); _callbackPtr = Marshal.GetFunctionPointerForDelegate(_d); var err = libspotify.sp_image_add_load_callback(this.ImagePtr, _callbackPtr, IntPtr.Zero); if (err != libspotify.sp_error.OK) throw new ApplicationException("Unable to add image load callbacks"); }
private void beginLoad() { _d = new image_loaded_cb_delegate(onImageLoaded); _callbackPtr = Marshal.GetFunctionPointerForDelegate(_d); libspotify.sp_image_add_load_callback(ImagePtr, _callbackPtr, IntPtr.Zero); }