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); } } }
public bool BeginBrowse() { try { _d = new artistbrowse_complete_cb_delegate(this.artistbrowse_complete); IntPtr callbackPtr = Marshal.GetFunctionPointerForDelegate(_d); _browsePtr = libspotify.sp_artistbrowse_create(Session.GetSessionPtr(), this.ArtistPtr, libspotify.sp_artistbrowse_type.SP_ARTISTBROWSE_NO_TRACKS, callbackPtr, IntPtr.Zero); return(true); } catch (Exception ex) { Logger.WriteDebug("Album.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); } } }
public bool BeginBrowse() { try { _d = new artistbrowse_complete_cb_delegate(this.artistbrowse_complete); IntPtr callbackPtr = Marshal.GetFunctionPointerForDelegate(_d); _browsePtr = libspotify.sp_artistbrowse_create(_session.GetSessionPtr(), this.ArtistPtr, libspotify.sp_artistbrowse_type.SP_ARTISTBROWSE_NO_TRACKS, callbackPtr, IntPtr.Zero); return true; } catch (Exception ex) { throw new Exception(string.Format("Album.BeginBrowse() failed: {0}", ex.Message)); } }
public bool BeginBrowse() { try { _d = new artistbrowse_complete_cb_delegate(this.artistbrowse_complete); IntPtr callbackPtr = Marshal.GetFunctionPointerForDelegate(_d); _browsePtr = libspotify.sp_artistbrowse_create(Session.SessionPtr, this.ArtistPtr, libspotify.sp_artistbrowse_type.SP_ARTISTBROWSE_NO_TRACKS, callbackPtr, IntPtr.Zero); return true; } catch (Exception ex) { Log.Error(Plugin.LOG_MODULE, "Album.BeginBrowse() failed: {0}", ex.Message); return false; } }