Пример #1
0
        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);
                }
            }
        }
Пример #2
0
        public bool BeginBrowse()
        {
            try {
                _d = new albumbrowse_complete_cb_delegate(this.albumbrowse_complete);
                IntPtr callbackPtr = Marshal.GetFunctionPointerForDelegate(_d);
                _browsePtr = libspotify.sp_albumbrowse_create(Session.GetSessionPtr(), this.AlbumPtr, callbackPtr, IntPtr.Zero);

                return(true);
            } catch (Exception ex) {
                Logger.WriteDebug("Album.BeginBrowse() failed: {0}", ex.Message);
                return(false);
            }
        }
Пример #3
0
        public bool BeginBrowse()
        {
            try {

                _d = new albumbrowse_complete_cb_delegate(this.albumbrowse_complete);
                IntPtr callbackPtr = Marshal.GetFunctionPointerForDelegate(_d);
                _browsePtr = libspotify.sp_albumbrowse_create(Session.GetSessionPtr(), this.AlbumPtr, callbackPtr, IntPtr.Zero);

                return true;

            } catch (Exception ex) {

                Log.Warning(Plugin.LOG_MODULE, "Album.BeginBrowse() failed: {0}", ex.Message);
                return false;

            }
        }
Пример #4
0
        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);
                }
            }
        }
Пример #5
0
        public bool BeginBrowse()
        {
            try {

                _d = new albumbrowse_complete_cb_delegate(this.albumbrowse_complete);
                IntPtr callbackPtr = Marshal.GetFunctionPointerForDelegate(_d);
                _browsePtr = libspotify.sp_albumbrowse_create(_session.GetSessionPtr(), this.AlbumPtr, callbackPtr, IntPtr.Zero);

                return true;

            } catch (Exception ex) {

                throw new Exception(string.Format("Album.BeginBrowse() failed: {0}", ex.Message));

            }
        }