Ejemplo n.º 1
0
        public List <PlaylistInfo> GetAllPlaylists()
        {
            if (!GetSessionContainer().IsLoaded)
            {
                throw new InvalidOperationException("Container is not loaded.");
            }

            List <PlaylistInfo> playlists = new List <PlaylistInfo>();

            for (int i = 0; i < libspotify.sp_playlistcontainer_num_playlists(_containerPtr); i++)
            {
                if (libspotify.sp_playlistcontainer_playlist_type(_containerPtr, i) == libspotify.sp_playlist_type.SP_PLAYLIST_TYPE_PLAYLIST)
                {
                    IntPtr playlistPtr = libspotify.sp_playlistcontainer_playlist(_containerPtr, i);

                    playlists.Add(new PlaylistInfo()
                    {
                        Pointer      = playlistPtr,
                        PlaylistType = libspotify.sp_playlist_type.SP_PLAYLIST_TYPE_PLAYLIST,
                        ContainerPtr = _containerPtr,
                        Name         = Functions.PtrToString(libspotify.sp_playlist_name(playlistPtr))
                    });
                }
            }

            return(playlists);
        }
Ejemplo n.º 2
0
        public Artist(IntPtr artistPtr)
        {
            if (artistPtr == IntPtr.Zero)
            {
                throw new InvalidOperationException("Artist pointer is null.");
            }

            this.ArtistPtr = artistPtr;
            this.Name      = Functions.PtrToString(libspotify.sp_artist_name(artistPtr));
        }
Ejemplo n.º 3
0
 private void populateMetadata()
 {
     this.Name            = Functions.PtrToString(libspotify.sp_playlist_name(this.Pointer));
     this.TrackCount      = libspotify.sp_playlist_num_tracks(this.Pointer);
     this.Description     = Functions.PtrToString(libspotify.sp_playlist_get_description(this.Pointer));
     this.SubscriberCount = (int)libspotify.sp_playlist_num_subscribers(this.Pointer);
     this.IsInRAM         = libspotify.sp_playlist_is_in_ram(Session.SessionPtr, this.Pointer);
     this.OfflineStatus   = libspotify.sp_playlist_get_offline_status(Session.SessionPtr, this.Pointer);
     this.TrackCount      = libspotify.sp_playlist_num_tracks(this.Pointer);
 }
Ejemplo n.º 4
0
        public User(IntPtr userPtr)
        {
            if (!libspotify.sp_user_is_loaded(userPtr))
            {
                throw new InvalidOperationException("User is not loaded.");
            }

            this.UserPtr       = userPtr;
            this.CanonicalName = Functions.PtrToString(libspotify.sp_user_canonical_name(userPtr));
            this.DisplayName   = Functions.PtrToString(libspotify.sp_user_display_name(userPtr));
        }
Ejemplo n.º 5
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;
        }
Ejemplo n.º 6
0
        public 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);
            }
        }
Ejemplo n.º 7
0
        public async Task <bool> InitAsync()
        {
            if (Loaded)
            {
                return(true);
            }

            if (!libspotify.sp_track_is_loaded(this.TrackPtr))
            {
                // Queue this track to get initted by spotify thread
                if (!ToInitialize.Contains(this))
                {
                    ToInitialize.Add(this);
                }
                return(false);
            }

            this.Name        = Functions.PtrToString(libspotify.sp_track_name(this.TrackPtr));
            this.TrackNumber = libspotify.sp_track_index(this.TrackPtr);
            this.Seconds     = (decimal)libspotify.sp_track_duration(this.TrackPtr) / 1000M;
            this._albumPtr   = libspotify.sp_track_album(this.TrackPtr);
            if (_albumPtr != IntPtr.Zero)
            {
                this.Album = new Album(_albumPtr);
            }

            for (int i = 0; i < libspotify.sp_track_num_artists(this.TrackPtr); i++)
            {
                IntPtr artistPtr = libspotify.sp_track_artist(this.TrackPtr, i);
                if (artistPtr != IntPtr.Zero)
                {
                    _artists.Add(Functions.PtrToString(libspotify.sp_artist_name(artistPtr)));
                }
            }

            if (fetchArt)
            {
                await GetAlbumArtAsync();
            }

            if (onLoad != null)
            {
                onLoad();
            }
            this.Loaded = true;
            return(true);
        }
Ejemplo n.º 8
0
        public Album(IntPtr albumPtr)
        {
            if (albumPtr == IntPtr.Zero)
            {
                throw new InvalidOperationException("Album pointer is null.");
            }

            this.AlbumPtr = albumPtr;
            this.Name     = Functions.PtrToString(libspotify.sp_album_name(albumPtr));
            this.Type     = libspotify.sp_album_type(albumPtr);
            IntPtr artistPtr = libspotify.sp_album_artist(albumPtr);

            if (artistPtr != IntPtr.Zero)
            {
                this.Artist = Functions.PtrToString(libspotify.sp_artist_name(artistPtr));
            }
        }
Ejemplo n.º 9
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)
            {
                Log.Warning(Plugin.LOG_MODULE, "ERROR: Search failed: {0}", Functions.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 = Functions.PtrToString(libspotify.sp_search_playlist_uri(_searchPtr, i)),
                    Name = Functions.PtrToString(libspotify.sp_search_playlist_name(_searchPtr, i)),
                });
            }

            this.IsLoaded = true;
        }
Ejemplo n.º 10
0
        public static void Login(object[] args)
        {
            appkey = (byte[])args[0];

            if (_sessionPtr == IntPtr.Zero)
            {
                _loginError = initSession((string)args[3]);
            }

            if (_loginError != libspotify.sp_error.OK)
            {
                throw new ApplicationException(Functions.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);
        }