Beispiel #1
0
        private void albumbrowse_complete(IntPtr result, IntPtr userDataPtr)
        {
            try
            {
                libspotify.sp_error error = libspotify.sp_albumbrowse_error(result);

                if (error != libspotify.sp_error.OK)
                {
                    Spotify.Log.DebugFormat("Album browse failed: {0}", libspotify.sp_error_message(error));
                    return;
                }

                int numtracks = libspotify.sp_albumbrowse_num_tracks(_browsePtr);

                List <IntPtr> trackPtrs = new List <IntPtr>();

                for (int i = 0; i < libspotify.sp_albumbrowse_num_tracks(_browsePtr); i++)
                {
                    trackPtrs.Add(libspotify.sp_albumbrowse_track(_browsePtr, i));
                }

                this.TrackPtrs = trackPtrs;

                this.IsBrowseComplete = true;
            }
            finally
            {
                safeReleaseAlbum();
            }
        }
Beispiel #2
0
        public static void ShutDown()
        {
            LogTo.Warn("Shutdown");
            lock (_syncObj)
            {
                if (_mainSignal != null)
                {
                    _mainSignal.Set();
                }
                _mainSignal = null;
                _t          = null;
                _shutDown   = true;

                if (Session.SessionPtr != IntPtr.Zero)
                {
                    try
                    {
                        libspotify.sp_error err = libspotify.sp_session_player_unload(Session.SessionPtr);
                        err = libspotify.sp_session_logout(Session.SessionPtr);
                        err = libspotify.sp_session_release(Session.SessionPtr);
                    }
                    catch (Exception ex)
                    {
                        Log.Warning(LOG_MODULE, "Error cleaning up session", ex);
                    }
                }
                _isLoggedIn = false;
                _initted    = false;
            }

            _programSignal.WaitOne(2000, false);
            _programSignal = null;
        }
Beispiel #3
0
        public static void ShutDown()
        {
            lock (SyncObject)
            {
                if (_mainSignal != null)
                {
                    _mainSignal.Set();
                }
                _mainSignal = null;
                _t          = null;
                _shutDown   = true;

                if (Session.SessionPtr != IntPtr.Zero)
                {
                    try
                    {
                        libspotify.sp_error err = libspotify.sp_session_player_unload(Session.SessionPtr);
                        err = libspotify.sp_session_logout(Session.SessionPtr);
                        err = libspotify.sp_session_release(Session.SessionPtr);
                        Spotify.Log.DebugFormat("Successfully closed libspotify session.");
                    }
                    catch (Exception ex)
                    {
                        Spotify.Log.ErrorFormat("Error cleaning up session: {0}", ex);
                    }
                }
                _isLoggedIn = false;
                _initted    = false;
            }

            _programSignal.WaitOne(2000, false);
            _programSignal = null;
        }
Beispiel #4
0
        private void Albumbrowse_Completed(IntPtr result, IntPtr userDataPtr)
        {
            try
            {
                libspotify.sp_error error = libspotify.sp_albumbrowse_error(result);

                if (error != libspotify.sp_error.OK)
                {
                    return;
                }

                int numtracks = libspotify.sp_albumbrowse_num_tracks(_browsePtr);

                List <IntPtr> trackPtrs = new List <IntPtr>();

                for (int i = 0; i < libspotify.sp_albumbrowse_num_tracks(_browsePtr); i++)
                {
                    trackPtrs.Add(libspotify.sp_albumbrowse_track(_browsePtr, i));
                }

                this.TrackPointers = trackPtrs;

                this.IsBrowseComplete = true;
            }
            finally
            {
                SafeReleaseAlbum();
            }
        }
Beispiel #5
0
        public static bool Login(string username = null, string password = null)
        {
            if (_sessionPtr == IntPtr.Zero)
            {
                _loginError = initSession();
            }

            if (_loginError != libspotify.sp_error.OK)
            {
                throw new ApplicationException("Failed to login");
            }
            //throw new ApplicationException(libspotify.sp_error_message(_loginError));

            if (_sessionPtr == IntPtr.Zero)
            {
                throw new InvalidOperationException("Session initialization failed, session pointer is null.");
            }

            if (username != null && password != null && username.Length > 0 && password.Length > 0)
            {
                bool bb = libspotify.sp_session_login(_sessionPtr, username, password, true, null) == libspotify.sp_error.OK;
                Log.Debug("Did login succeed?: " + bb);
                return(bb);
            }
            else
            {
                bool b = libspotify.sp_session_relogin(_sessionPtr) == libspotify.sp_error.OK;
                Log.Debug("Did relogin succeed?: " + b);
                return(b);
            }
        }
Beispiel #6
0
        private static libspotify.sp_error initSession()
        {
            libspotify.sp_session_callbacks callbacks = new libspotify.sp_session_callbacks();
            callbacks.connection_error       = Marshal.GetFunctionPointerForDelegate(fn_connection_error_delegate);
            callbacks.end_of_track           = Marshal.GetFunctionPointerForDelegate(fn_end_of_track_delegate);
            callbacks.get_audio_buffer_stats = Marshal.GetFunctionPointerForDelegate(fn_get_audio_buffer_stats_delegate);
            callbacks.log_message            = Marshal.GetFunctionPointerForDelegate(fn_log_message);
            callbacks.logged_in              = Marshal.GetFunctionPointerForDelegate(fn_logged_in_delegate);
            callbacks.logged_out             = Marshal.GetFunctionPointerForDelegate(fn_logged_out_delegate);
            callbacks.message_to_user        = Marshal.GetFunctionPointerForDelegate(fn_message_to_user_delegate);
            callbacks.metadata_updated       = Marshal.GetFunctionPointerForDelegate(fn_metadata_updated_delegate);
            callbacks.music_delivery         = Marshal.GetFunctionPointerForDelegate(fn_music_delivery_delegate);
            callbacks.notify_main_thread     = Marshal.GetFunctionPointerForDelegate(fn_notify_main_thread_delegate);
            callbacks.offline_status_updated = Marshal.GetFunctionPointerForDelegate(fn_offline_status_updated_delegate);
            callbacks.play_token_lost        = Marshal.GetFunctionPointerForDelegate(fn_play_token_lost_delegate);
            callbacks.start_playback         = Marshal.GetFunctionPointerForDelegate(fn_start_playback);
            callbacks.stop_playback          = Marshal.GetFunctionPointerForDelegate(fn_stop_playback);
            callbacks.streaming_error        = Marshal.GetFunctionPointerForDelegate(fn_streaming_error_delegate);
            callbacks.userinfo_updated       = Marshal.GetFunctionPointerForDelegate(fn_userinfo_updated_delegate);

            IntPtr callbacksPtr = Marshal.AllocHGlobal(Marshal.SizeOf(callbacks));

            Marshal.StructureToPtr(callbacks, callbacksPtr, true);

            libspotify.sp_session_config config = new libspotify.sp_session_config();
            config.api_version                      = libspotify.SPOTIFY_API_VERSION;
            config.user_agent                       = "BlindSpot";
            config.application_key_size             = appkey.Length;
            config.application_key                  = Marshal.AllocHGlobal(appkey.Length);
            config.cache_location                   = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Blindspot\\Libspotify");
            config.settings_location                = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Blindspot\\Libspotify");
            config.callbacks                        = callbacksPtr;
            config.compress_playlists               = true;
            config.dont_save_metadata_for_playlists = false;
            config.initially_unload_playlists       = false;

            Logger.WriteDebug("api_version={0}", config.api_version);
            Logger.WriteDebug("application_key_size={0}", config.application_key_size);
            Logger.WriteDebug("cache_location={0}", config.cache_location);
            Logger.WriteDebug("settings_location={0}", config.settings_location);

            Marshal.Copy(appkey, 0, config.application_key, appkey.Length);

            IntPtr sessionPtr;

            libspotify.sp_error err = libspotify.sp_session_create(ref config, out sessionPtr);

            if (err == libspotify.sp_error.OK)
            {
                _sessionPtr = sessionPtr;
                libspotify.sp_session_set_connection_type(sessionPtr, libspotify.sp_connection_type.SP_CONNECTION_TYPE_WIRED);
            }

            return(err);
        }
Beispiel #7
0
 private static void logged_in(IntPtr sessionPtr, libspotify.sp_error error)
 {
     if (error == libspotify.sp_error.OK)
     {
         _isLoggedIn = true;
     }
     _loginError = error;
     if (Session.OnLoggedIn != null)
     {
         Session.OnLoggedIn(sessionPtr);
     }
 }
        private string getFolderName(IntPtr containerPtr, int index)
        {
            IntPtr namePtr = Marshal.AllocHGlobal(128);

            try {
                libspotify.sp_error error = libspotify.sp_playlistcontainer_playlist_folder_name(containerPtr, index, namePtr, 128);

                return(Functions.PtrToString(namePtr));
            } finally {
                Marshal.FreeHGlobal(namePtr);
            }
        }
Beispiel #9
0
        private void toplistbrowse_complete(IntPtr result, IntPtr userDataPtr)
        {
            if (_browsePtr == IntPtr.Zero)
            {
                throw new ApplicationException("Toplist browse is null");
            }

            libspotify.sp_error error = libspotify.sp_toplistbrowse_error(_browsePtr);

            if (error != libspotify.sp_error.OK)
            {
                Log.Warning(Plugin.LOG_MODULE, "ERROR: Toplist browse failed: {0}", Functions.PtrToString(libspotify.sp_error_message(error)));
                this.IsLoaded = true;
                return;
            }

            if (_browsePtr == IntPtr.Zero)
            {
                throw new ApplicationException("Toplist browse is null");
            }

            int count = this.ToplistType == libspotify.sp_toplisttype.SP_TOPLIST_TYPE_ALBUMS ? libspotify.sp_toplistbrowse_num_albums(_browsePtr) : this.ToplistType == libspotify.sp_toplisttype.SP_TOPLIST_TYPE_ARTISTS ? libspotify.sp_toplistbrowse_num_artists(_browsePtr) : libspotify.sp_toplistbrowse_num_tracks(_browsePtr);

            List <IntPtr> ptrs = new List <IntPtr>();

            IntPtr tmp = IntPtr.Zero;

            for (int i = 0; i < count; i++)
            {
                if (this.ToplistType == libspotify.sp_toplisttype.SP_TOPLIST_TYPE_ALBUMS)
                {
                    tmp = libspotify.sp_toplistbrowse_album(_browsePtr, i);
                    if (libspotify.sp_album_is_available(tmp))
                    {
                        ptrs.Add(tmp);
                    }
                }
                else if (this.ToplistType == libspotify.sp_toplisttype.SP_TOPLIST_TYPE_ARTISTS)
                {
                    tmp = libspotify.sp_toplistbrowse_artist(_browsePtr, i);
                    ptrs.Add(tmp);
                }
                else
                {
                    tmp = libspotify.sp_toplistbrowse_track(_browsePtr, i);
                    ptrs.Add(tmp);
                }
            }
            this.Ptrs     = ptrs;
            this.IsLoaded = true;
        }
        private void toplistbrowse_complete(IntPtr result, IntPtr userDataPtr)
        {
            try
            {
                libspotify.sp_error error = libspotify.sp_toplistbrowse_error(result);

                if (error != libspotify.sp_error.OK)
                {
                    return;
                }

                int count = this.ToplistType == libspotify.sp_toplisttype.SP_TOPLIST_TYPE_ALBUMS ? libspotify.sp_toplistbrowse_num_albums(_browsePtr) : this.ToplistType == libspotify.sp_toplisttype.SP_TOPLIST_TYPE_ARTISTS ? libspotify.sp_toplistbrowse_num_artists(_browsePtr) : libspotify.sp_toplistbrowse_num_tracks(_browsePtr);

                List <IntPtr> ptrs = new List <IntPtr>();

                IntPtr tmp = IntPtr.Zero;

                for (int i = 0; i < count; i++)
                {
                    if (this.ToplistType == libspotify.sp_toplisttype.SP_TOPLIST_TYPE_ALBUMS)
                    {
                        tmp = libspotify.sp_toplistbrowse_album(_browsePtr, i);
                        if (libspotify.sp_album_is_available(tmp))
                        {
                            ptrs.Add(tmp);
                        }
                    }
                    else if (this.ToplistType == libspotify.sp_toplisttype.SP_TOPLIST_TYPE_ARTISTS)
                    {
                        tmp = libspotify.sp_toplistbrowse_artist(_browsePtr, i);
                        ptrs.Add(tmp);
                    }
                    else
                    {
                        tmp = libspotify.sp_toplistbrowse_track(_browsePtr, i);
                        ptrs.Add(tmp);
                    }
                }

                this.Ptrs = ptrs;

                this.IsLoaded = true;
            }
            finally
            {
                safeReleaseToplist();
            }
        }
Beispiel #11
0
        private void search_complete(IntPtr result, IntPtr userDataPtr)
        {
            if (_searchPtr == IntPtr.Zero)
            {
                throw new ApplicationException("Search pointer is null");
            }

            libspotify.sp_error error = libspotify.sp_search_error(_searchPtr);

            if (error != libspotify.sp_error.OK)
            {
                Spotify.Log.ErrorFormat("ERROR: Search failed: {0}", Utils.PtrToString(libspotify.sp_error_message(error)));
                this.IsLoaded = true;
                return;
            }

            this.TrackPtrs = new List <IntPtr>();
            for (int i = 0; i < libspotify.sp_search_num_tracks(_searchPtr); i++)
            {
                this.TrackPtrs.Add(libspotify.sp_search_track(_searchPtr, i));
            }

            this.ArtistPtrs = new List <IntPtr>();
            for (int i = 0; i < libspotify.sp_search_num_artists(_searchPtr); i++)
            {
                this.ArtistPtrs.Add(libspotify.sp_search_artist(_searchPtr, i));
            }

            this.AlbumPtrs = new List <IntPtr>();
            for (int i = 0; i < libspotify.sp_search_num_albums(_searchPtr); i++)
            {
                this.AlbumPtrs.Add(libspotify.sp_search_album(_searchPtr, i));
            }

            this.PlaylistResults = new List <PlaylistSearchResult>();
            for (int i = 0; i < libspotify.sp_search_num_playlists(_searchPtr); i++)
            {
                this.PlaylistResults.Add(new PlaylistSearchResult()
                {
                    Link = Utils.PtrToString(libspotify.sp_search_playlist_uri(_searchPtr, i)),
                    Name = Utils.PtrToString(libspotify.sp_search_playlist_name(_searchPtr, i)),
                });
            }

            this.IsLoaded = true;
        }
Beispiel #12
0
        private void Search_Complete_Callback(IntPtr result, IntPtr userDataPtr)
        {
            try
            {
                libspotify.sp_error error = libspotify.sp_search_error(result);

                if (error != libspotify.sp_error.OK)
                {
                    return;
                }

                var albumCount  = libspotify.sp_search_num_albums(_searchPtr);
                var artistCount = libspotify.sp_search_num_artists(_searchPtr);
                var trackCount  = libspotify.sp_search_num_tracks(_searchPtr);

                List <Album> albums = new List <Album>();
                for (int i = 0; i < albumCount; i++)
                {
                    var ptr = libspotify.sp_search_album(_searchPtr, i);
                    albums.Add(new Album(ptr));
                }

                List <Artist> artists = new List <Artist>();
                for (int i = 0; i < artistCount; i++)
                {
                    var ptr = libspotify.sp_search_artist(_searchPtr, i);
                    artists.Add(new Artist(ptr));
                }

                List <Track> tracks = new List <Track>();
                for (int i = 0; i < trackCount; i++)
                {
                    var ptr = libspotify.sp_search_track(_searchPtr, i);
                    tracks.Add(new Track(ptr));
                }

                this.Albums   = albums;
                this.Artists  = artists;
                this.Tracks   = tracks;
                this.IsLoaded = true;
            }
            finally
            {
                safeReleaseToplist();
            }
        }
Beispiel #13
0
        private void init(IntPtr trackPtr)
        {
            Log.Debug("Track.init() - begin sp_track_is_loaded loop...");
            var startLoadTime = DateTime.Now;
            int timeout       = 0;

            while (!libspotify.sp_track_is_loaded(trackPtr))
            {
                Thread.Sleep(20);
                if (DateTime.Now.Subtract(startLoadTime) > TimeSpan.FromSeconds(10))
                {
                    libspotify.sp_error error = libspotify.sp_track_error(trackPtr);

                    Log.Error("Track is not loaded after 10 seconds - " + TrackId + " - " + error);
                    throw new InvalidOperationException("Track is not loaded after 10 seconds - " + TrackId + " - " + error);
                }

                libspotify.sp_session_process_events(Session.SessionPtr, out timeout);
            }

            this.TrackPtr          = trackPtr;
            this.Name              = Utils.PtrToString(libspotify.sp_track_name(trackPtr));
            this.TrackNumber       = libspotify.sp_track_index(trackPtr);
            this.Seconds           = (decimal)libspotify.sp_track_duration(trackPtr) / 1000M;
            this.LengthMiliseconds = libspotify.sp_track_duration(trackPtr);

            IntPtr albumPtr = libspotify.sp_track_album(trackPtr);

            if (albumPtr != IntPtr.Zero)
            {
                this.Album = new Album(albumPtr);
            }

            for (int i = 0; i < libspotify.sp_track_num_artists(trackPtr); i++)
            {
                IntPtr artistPtr = libspotify.sp_track_artist(trackPtr, i);
                if (artistPtr != IntPtr.Zero)
                {
                    _artists.Add(Utils.PtrToString(libspotify.sp_artist_name(artistPtr)));
                }
            }
            Log.Debug("Track.init() - loaded '" + Name + "' successfully");
        }
Beispiel #14
0
        private static void logged_in(IntPtr sessionPtr, libspotify.sp_error error)
        {
            if (error == libspotify.sp_error.OK)
            {
                Log.Debug("Logged in callback!");
                _isLoggedIn = true;
            }
            else
            {
                Log.Debug("Login issue in logged_in callback! " + error.ToString());
            }

            _loginError = error;

            if (Session.OnLoggedIn != null)
            {
                Session.OnLoggedIn(sessionPtr);
            }
        }
Beispiel #15
0
        public static void Login(object[] args)
        {
            Session.appkey = (byte[])args[0];

            if (_sessionPtr == IntPtr.Zero)
            {
                _loginError = initSession();
            }

            if (_loginError != libspotify.sp_error.OK)
            {
                throw new ApplicationException(Utils.PtrToString(libspotify.sp_error_message(_loginError)));
            }

            if (_sessionPtr == IntPtr.Zero)
            {
                throw new InvalidOperationException("Session initialization failed, session pointer is null.");
            }

            libspotify.sp_session_login(_sessionPtr, args[1].ToString(), args[2].ToString(), false, null);
        }
Beispiel #16
0
        /// <summary>
        /// Initiate a new Spotify Session using the provided configuration, username and password. Please note that using multiple sessions per application is unsupported.
        /// </summary>
        /// <param name="Username">The username to login with.</param>
        /// <param name="Password">The password to login with. You may not store this as plaintext according to the libspotify Terms of Use.</param>
        /// <param name="Configuration">The session configuration to use.</param>
        public SpotifySession(string Username, string Password, SpotifySessionConfig Configuration)
        {
            libspotify.sp_session_config sessionconfig = new libspotify.sp_session_config();
            sessionconfig.api_version = Configuration.APIVersion;
            IntPtr apikey = Marshal.AllocHGlobal(Configuration.APIKey.Length);
            Marshal.Copy(Configuration.APIKey, 0, apikey, Configuration.APIKey.Length);
            sessionconfig.application_key = apikey;
            sessionconfig.application_key_size = Configuration.APIKey.Length;
            sessionconfig.cache_location = Configuration.CacheLocation;
            sessionconfig.device_id = Configuration.DeviceID;
            sessionconfig.compress_playlists = Configuration.CompressPlaylists;
            sessionconfig.dont_save_metadata_for_playlists = Configuration.DontSaveMetadataForPlaylists;
            sessionconfig.initially_unload_playlists = Configuration.InitiallyUnloadPlaylists;
            sessionconfig.settings_location = Configuration.SettingsLocation;
            sessionconfig.user_agent = Configuration.UserAgent;
            //TODO: Implement callbacks to get music streams etc.
            //TODO: Fix the proxy below, needs to get type.
            /*sessionconfig.proxy = Configuration.Proxy.GetProxy(new Uri("http://spotify.com/")).AbsoluteUri; //Should be correct. I think.
            sessionconfig.proxy_username = Configuration.Proxy.Credentials.GetCredential(new Uri("http://spotify.com/"),*/
            sessionconfig.ca_certs_filename = Configuration.CACertsName;
            libspotify.sp_session_callbacks callbacks = new libspotify.sp_session_callbacks();
            callbacks.music_delivery = Marshal.GetFunctionPointerForDelegate(mdd);
            IntPtr callbacksNative = Marshal.AllocHGlobal(Marshal.SizeOf(callbacks));
            Marshal.StructureToPtr(callbacks, callbacksNative, true);
            sessionconfig.callbacks = callbacksNative;

            temp = libspotify.sp_session_create(ref sessionconfig, out spotsession);
            if (temp != libspotify.sp_error.OK)
            {
                SpotifyExceptions.SessionCreateFailedException exc = new SpotifyExceptions.SessionCreateFailedException(libspotify.sp_error_message(temp));
                throw exc;
            }
            temp = libspotify.sp_session_login(spotsession, Username, Password, false, null);
            if (temp != libspotify.sp_error.OK)
            {
                SpotifyExceptions.LoginFailedException exc = new SpotifyExceptions.LoginFailedException(libspotify.sp_error_message(temp));
                throw exc;
            }
        }
Beispiel #17
0
        private void artistbrowse_complete(IntPtr result, IntPtr userDataPtr)
        {
            try {
                libspotify.sp_error error = libspotify.sp_artistbrowse_error(result);

                if (error != libspotify.sp_error.OK)
                {
                    Logger.WriteDebug("Artist browse failed: {0}", libspotify.sp_error_message(error));
                    return;
                }

                int numalbums = libspotify.sp_artistbrowse_num_albums(_browsePtr);

                List <IntPtr> albumPtrs = new List <IntPtr>();

                for (int i = 0; i < libspotify.sp_artistbrowse_num_albums(_browsePtr); i++)
                {
                    IntPtr albumPtr = libspotify.sp_artistbrowse_album(_browsePtr, i);

                    // excluding singles, compilations, and unknowns
                    if (libspotify.sp_album_type(albumPtr) == libspotify.sp_albumtype.SP_ALBUMTYPE_ALBUM &&
                        libspotify.sp_album_is_available(albumPtr))
                    {
                        albumPtrs.Add(albumPtr);
                    }
                }

                this.AlbumPtrs = albumPtrs;

                // need to decide how we want this to work. a refactor may be in order around starting a browse
                // ideas include Lazy artist browsing (not that artists are lazy)
                //this.SpotifyBio = Functions.PtrToString(libspotify.sp_artistbrowse_biography(_browsePtr));

                this.IsBrowseComplete = true;
            } finally {
                safeReleaseArtist();
            }
        }
Beispiel #18
0
        private void artistbrowse_complete(IntPtr result, IntPtr userDataPtr)
        {
            try
            {
                libspotify.sp_error error = libspotify.sp_artistbrowse_error(result);

                if (error != libspotify.sp_error.OK)
                {
                    Log.Error(Plugin.LOG_MODULE, "Artist browse failed: {0}", libspotify.sp_error_message(error));
                    return;
                }

                int numalbums = libspotify.sp_artistbrowse_num_albums(_browsePtr);

                List <IntPtr> albumPtrs = new List <IntPtr>();

                for (int i = 0; i < libspotify.sp_artistbrowse_num_albums(_browsePtr); i++)
                {
                    IntPtr albumPtr = libspotify.sp_artistbrowse_album(_browsePtr, i);

                    // excluding singles, compilations, and unknowns
                    if (libspotify.sp_album_type(albumPtr) == libspotify.sp_albumtype.SP_ALBUMTYPE_ALBUM &&
                        libspotify.sp_album_is_available(albumPtr))
                    {
                        albumPtrs.Add(albumPtr);
                    }
                }

                this.AlbumPtrs = albumPtrs;

                this.IsBrowseComplete = true;
            }
            finally
            {
                safeReleaseArtist();
            }
        }
        private void Artistbrowse_Completed(IntPtr result, IntPtr userDataPtr)
        {
            try
            {
                libspotify.sp_error error = libspotify.sp_artistbrowse_error(result);

                if (error != libspotify.sp_error.OK)
                {
                    return;
                }

                int numalbums = libspotify.sp_artistbrowse_num_albums(_browsePointer);

                List <IntPtr> albumPtrs = new List <IntPtr>();

                for (int i = 0; i < libspotify.sp_artistbrowse_num_albums(_browsePointer); i++)
                {
                    IntPtr albumPtr = libspotify.sp_artistbrowse_album(_browsePointer, i);

                    // excluding singles, compilations, and unknowns
                    if (libspotify.sp_album_type(albumPtr) == libspotify.sp_albumtype.SP_ALBUMTYPE_ALBUM &&
                        libspotify.sp_album_is_available(albumPtr))
                    {
                        albumPtrs.Add(albumPtr);
                    }
                }

                this.AlbumPointers = albumPtrs;

                this.IsBrowseComplete = true;
            }
            finally
            {
                SafeReleaseArtist();
            }
        }
Beispiel #20
0
 private void SearchCompleted(IntPtr searchPtr, IntPtr userDataPtr)
 {
     libspotify.sp_error error = libspotify.sp_search_error(searchPtr);
     if (error != libspotify.sp_error.OK)
     {
         Logger.WriteDebug("Search browse failed: {0}", libspotify.sp_error_message(error));
         this.IsLoaded = true;
         return;
     }
     this.DidYouMean = Functions.PtrToString(libspotify.sp_search_did_you_mean(_browsePtr));
     if (this.Type == SearchType.Track)
     {
         LoadTracks();
     }
     else if (this.Type == SearchType.Album)
     {
         LoadAlbums();
     }
     else if (this.Type == SearchType.Artist)
     {
         LoadArtists();
     }
     this.IsLoaded = true;
 }
Beispiel #21
0
 private static void connection_error(IntPtr sessionPtr, libspotify.sp_error error)
 {
     Log.Error("Connection error: {0}", libspotify.sp_error_message(error));
 }
Beispiel #22
0
        private static void logged_in(IntPtr sessionPtr, libspotify.sp_error error)
        {
            if (error == libspotify.sp_error.OK)
            {
                _isLoggedIn = true;
            }

            _loginError = error;

            if (Session.OnLoggedIn != null)
                Session.OnLoggedIn(sessionPtr);
        }
Beispiel #23
0
        public static void Login(object[] args)
        {
            Session.appkey = (byte[])args[0];

            if (_sessionPtr == IntPtr.Zero)
                _loginError = initSession();

            if (_loginError != libspotify.sp_error.OK)
                throw new ApplicationException(Utils.PtrToString(libspotify.sp_error_message(_loginError)));

            if (_sessionPtr == IntPtr.Zero)
                throw new InvalidOperationException("Session initialization failed, session pointer is null.");

            libspotify.sp_session_login(_sessionPtr, args[1].ToString(), args[2].ToString(), false, null);
        }
Beispiel #24
0
        private static libspotify.sp_error initSession(string appname)
        {
            libspotify.sp_session_callbacks callbacks = new libspotify.sp_session_callbacks();
            callbacks.connection_error       = Marshal.GetFunctionPointerForDelegate(fn_connection_error_delegate);
            callbacks.end_of_track           = Marshal.GetFunctionPointerForDelegate(fn_end_of_track_delegate);
            callbacks.get_audio_buffer_stats = Marshal.GetFunctionPointerForDelegate(fn_get_audio_buffer_stats_delegate);
            callbacks.log_message            = Marshal.GetFunctionPointerForDelegate(fn_log_message);
            callbacks.logged_in              = Marshal.GetFunctionPointerForDelegate(fn_logged_in_delegate);
            callbacks.logged_out             = Marshal.GetFunctionPointerForDelegate(fn_logged_out_delegate);
            callbacks.message_to_user        = Marshal.GetFunctionPointerForDelegate(fn_message_to_user_delegate);
            callbacks.metadata_updated       = Marshal.GetFunctionPointerForDelegate(fn_metadata_updated_delegate);
            callbacks.music_delivery         = Marshal.GetFunctionPointerForDelegate(fn_music_delivery_delegate);
            callbacks.notify_main_thread     = Marshal.GetFunctionPointerForDelegate(fn_notify_main_thread_delegate);
            callbacks.offline_status_updated = Marshal.GetFunctionPointerForDelegate(fn_offline_status_updated_delegate);
            callbacks.play_token_lost        = Marshal.GetFunctionPointerForDelegate(fn_play_token_lost_delegate);
            callbacks.start_playback         = Marshal.GetFunctionPointerForDelegate(fn_start_playback);
            callbacks.stop_playback          = Marshal.GetFunctionPointerForDelegate(fn_stop_playback);
            callbacks.streaming_error        = Marshal.GetFunctionPointerForDelegate(fn_streaming_error_delegate);
            callbacks.userinfo_updated       = Marshal.GetFunctionPointerForDelegate(fn_userinfo_updated_delegate);
            callbacks.scrobble_error         = Marshal.GetFunctionPointerForDelegate(fn_scrobble_error_delegate);

            IntPtr callbacksPtr = Marshal.AllocHGlobal(Marshal.SizeOf(callbacks));

            Marshal.StructureToPtr(callbacks, callbacksPtr, true);

            libspotify.sp_session_config config = new libspotify.sp_session_config();
            config.api_version                      = libspotify.SPOTIFY_API_VERSION;
            config.user_agent                       = appname;
            config.application_key_size             = appkey.Length;
            config.application_key                  = Marshal.AllocHGlobal(appkey.Length);
            config.cache_location                   = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), appname, "spotifycache");
            config.settings_location                = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), appname, "spotifysettings");
            config.callbacks                        = callbacksPtr;
            config.compress_playlists               = true;
            config.dont_save_metadata_for_playlists = false;
            config.initially_unload_playlists       = false;

            Log.Debug(Plugin.LOG_MODULE, "api_version={0}", config.api_version);
            Log.Debug(Plugin.LOG_MODULE, "application_key_size={0}", config.application_key_size);
            Log.Debug(Plugin.LOG_MODULE, "cache_location={0}", config.cache_location);
            Log.Debug(Plugin.LOG_MODULE, "settings_location={0}", config.settings_location);

            Marshal.Copy(appkey, 0, config.application_key, appkey.Length);

            IntPtr sessionPtr;

            libspotify.sp_error err = libspotify.sp_session_create(ref config, out sessionPtr);
            libspotify.sp_session_set_cache_size(sessionPtr, 0);

            if (err == libspotify.sp_error.OK)
            {
                _sessionPtr = sessionPtr;
                libspotify.sp_session_set_connection_type(sessionPtr, libspotify.sp_connection_type.SP_CONNECTION_TYPE_WIRED);
            }

            libspotify.sp_error test = libspotify.sp_session_preferred_bitrate(sessionPtr, libspotify.sp_bitrate.BITRATE_320k);
            if (test != libspotify.sp_error.OK)
            {
                Log.Warning(Plugin.LOG_MODULE, "sp_session_preferred_bitrate() failed: {0}", test);
            }
            else
            {
                Log.Debug(Plugin.LOG_MODULE, "sp_session_preferred_bitrate() succeeded!");
            }

            return(err);
        }
Beispiel #25
0
        private static libspotify.sp_error initSession()
        {
            lock (_lock)
            {
                waveOut = new WaveOut();

                libspotify.sp_session_callbacks callbacks = new libspotify.sp_session_callbacks();
                callbacks.connection_error       = Marshal.GetFunctionPointerForDelegate(fn_connection_error_delegate);
                callbacks.end_of_track           = Marshal.GetFunctionPointerForDelegate(fn_end_of_track_delegate);
                callbacks.get_audio_buffer_stats =
                    Marshal.GetFunctionPointerForDelegate(fn_get_audio_buffer_stats_delegate);
                callbacks.log_message            = Marshal.GetFunctionPointerForDelegate(fn_log_message);
                callbacks.logged_in              = Marshal.GetFunctionPointerForDelegate(fn_logged_in_delegate);
                callbacks.logged_out             = Marshal.GetFunctionPointerForDelegate(fn_logged_out_delegate);
                callbacks.message_to_user        = Marshal.GetFunctionPointerForDelegate(fn_message_to_user_delegate);
                callbacks.metadata_updated       = Marshal.GetFunctionPointerForDelegate(fn_metadata_updated_delegate);
                callbacks.music_delivery         = Marshal.GetFunctionPointerForDelegate(fn_music_delivery_delegate);
                callbacks.notify_main_thread     = Marshal.GetFunctionPointerForDelegate(fn_notify_main_thread_delegate);
                callbacks.offline_status_updated =
                    Marshal.GetFunctionPointerForDelegate(fn_offline_status_updated_delegate);
                callbacks.play_token_lost  = Marshal.GetFunctionPointerForDelegate(fn_play_token_lost_delegate);
                callbacks.start_playback   = Marshal.GetFunctionPointerForDelegate(fn_start_playback);
                callbacks.stop_playback    = Marshal.GetFunctionPointerForDelegate(fn_stop_playback);
                callbacks.streaming_error  = Marshal.GetFunctionPointerForDelegate(fn_streaming_error_delegate);
                callbacks.userinfo_updated = Marshal.GetFunctionPointerForDelegate(fn_userinfo_updated_delegate);

                IntPtr callbacksPtr = Marshal.AllocHGlobal(Marshal.SizeOf(callbacks));
                Marshal.StructureToPtr(callbacks, callbacksPtr, true);

                libspotify.sp_session_config config = new libspotify.sp_session_config();
                config.api_version                      = libspotify.SPOTIFY_API_VERSION;
                config.user_agent                       = "SoundBounce";
                config.application_key_size             = appkey.Length;
                config.application_key                  = Marshal.AllocHGlobal(appkey.Length);
                config.cache_location                   = Path.Combine(Path.GetTempPath(), "SoundBounce_temp");
                config.settings_location                = Path.Combine(Path.GetTempPath(), "SoundBounce_temp");
                config.callbacks                        = callbacksPtr;
                config.compress_playlists               = true;
                config.dont_save_metadata_for_playlists = false;
                config.initially_unload_playlists       = false;

                Spotify.Log.DebugFormat("api_version={0}", config.api_version);
                Spotify.Log.DebugFormat("api_version={0}", config.api_version);
                Spotify.Log.DebugFormat("application_key_size={0}", config.application_key_size);
                Spotify.Log.DebugFormat("cache_location={0}", config.cache_location);
                Spotify.Log.DebugFormat("settings_location={0}", config.settings_location);

                Marshal.Copy(appkey, 0, config.application_key, appkey.Length);

                IntPtr sessionPtr;
                libspotify.sp_error err = libspotify.sp_session_create(ref config, out sessionPtr);

                if (err == libspotify.sp_error.OK)
                {
                    _sessionPtr = sessionPtr;
                    libspotify.sp_session_set_connection_type(sessionPtr,
                                                              libspotify.sp_connection_type.SP_CONNECTION_TYPE_WIRED);
                }

                // set high bitrate

                if (ConfigurationManager.AppSettings["HighBitrate"] == "true")
                {
                    libspotify.sp_error test = libspotify.sp_session_preferred_bitrate(sessionPtr,
                                                                                       libspotify.sp_bitrate
                                                                                       .BITRATE_320k);
                    if (test != libspotify.sp_error.OK)
                    {
                        Spotify.Log.WarnFormat("sp_session_preferred_bitrate() to 320k failed: {0}", test);
                    }
                    else
                    {
                        Spotify.Log.Debug("sp_session_preferred_bitrate() to 320k succeeded!");
                    }
                }

                // normalize volume
                if (ConfigurationManager.AppSettings["NormalizeVolume"] == "true")
                {
                    libspotify.sp_session_set_volume_normalization(sessionPtr, true);
                }

                return(err);
            }
        }
Beispiel #26
0
 /// <summary>
 /// Starts buffering the Track inside the MusicStream object of the Session.
 /// </summary>
 /// <param name="Track">The SpotifyTrack to buffer.</param>
 public void playTrack(SpotifyTrack Track)
 {
     temp = libspotify.sp_session_player_load(spotsession, Track.internalTrack);
     temp = libspotify.sp_session_player_play(spotsession, true);
 }
 private static void streaming_error(IntPtr sessionPtr, libspotify.sp_error error)
 {
     //TODO Log.Error(Plugin.LOG_MODULE, "Streaming error: {0}", libspotify.sp_error_message(error));
 }
Beispiel #28
0
 private static void scrobble_error(IntPtr sessionptr, libspotify.sp_error error)
 {
     Log.Debug(Plugin.LOG_MODULE, "scrobble_error");
 }
Beispiel #29
0
 private static void streaming_error(IntPtr sessionPtr, libspotify.sp_error error)
 {
     Log.Error("Streaming error: {0}", libspotify.sp_error_message(error));
 }
Beispiel #30
0
        public static bool Login(string username = null, string password = null)
        {
            if (_sessionPtr == IntPtr.Zero)
                _loginError = initSession();

            if (_loginError != libspotify.sp_error.OK)
                throw new ApplicationException("Failed to login");
                //throw new ApplicationException(libspotify.sp_error_message(_loginError));

            if (_sessionPtr == IntPtr.Zero)
                throw new InvalidOperationException("Session initialization failed, session pointer is null.");

            if (username != null && password != null && username.Length > 0 && password.Length > 0)
            {
                bool bb = libspotify.sp_session_login(_sessionPtr, username, password, true, null) == libspotify.sp_error.OK;
                Log.Debug("Did login succeed?: " + bb);
                return (bb);
            }
            else
            {
                bool b = libspotify.sp_session_relogin(_sessionPtr) == libspotify.sp_error.OK;
                Log.Debug("Did relogin succeed?: " + b);
                return (b);
            }
        }
 private static void connection_error(IntPtr sessionPtr, libspotify.sp_error error)
 {
     //TODO Log.Error(Plugin.LOG_MODULE, "Connection error: {0}", libspotify.sp_error_message(error));
 }
Beispiel #32
0
        private static void logged_in(IntPtr sessionPtr, libspotify.sp_error error)
        {
            if (error == libspotify.sp_error.OK) {
                Log.Debug("Logged in callback!");
                _isLoggedIn = true;

            }
            else
            {
                Log.Debug("Login issue in logged_in callback! " + error.ToString());
            }

            _loginError = error;

            if (Session.OnLoggedIn != null)
                Session.OnLoggedIn(sessionPtr);
        }