Beispiel #1
0
        /// <summary>
        /// Bind the users list of playlists to the view
        /// </summary>
        /// <returns></returns>
        private async Task BindPlaylists()
        {
            try
            {
                var page = await SpotifyService.GetPlaylists(AuthenticationService.User, AuthenticationService.AuthenticationToken);

                do
                {
                    foreach (var playlist in page.Items)
                    {
                        Playlists.Add(playlist);
                    }

                    if (page.HasNextPage)
                    {
                        page = await SpotifyService.GetNextPage(page, AuthenticationService.AuthenticationToken);
                    }
                    else
                    {
                        page = null;
                    }
                }while (page != null);
            }
            catch (Exception ex)
            {
                PageException = ex;
            }

            Loaded = true;

            StateHasChanged();
        }
Beispiel #2
0
        /// <summary>
        /// Drop down list changed event to bind the playlist to the view
        /// </summary>
        /// <returns></returns>
        public async Task BindPlaylist(ChangeEventArgs e)
        {
            if (IsRandifying || IsPlaylistLoading)
            {
                return;
            }

            var playlistId = e.Value.ToString();

            try
            {
                IsPlaylistLoading    = true;
                Seconds              = 0;
                NumberOfLoadedTracks = 0;

                Stopwatch = new Stopwatch();
                Stopwatch.Start();
                PlaylistTracks.Clear();

                try
                {
                    var tracks = new List <PlaylistTrack>();

                    CurrentPlaylist = Playlists.FirstOrDefault(o => o.Id == playlistId);
                    var page = await SpotifyService.GetPlaylistTracks(AuthenticationService.User, AuthenticationService.AuthenticationToken, CurrentPlaylist);

                    do
                    {
                        foreach (var playlistTrack in page.Items)
                        {
                            tracks.Add(playlistTrack);
                        }

                        Seconds = Stopwatch.Elapsed.Seconds;
                        NumberOfLoadedTracks = tracks.Count();

                        StateHasChanged();

                        if (page.HasNextPage)
                        {
                            page = await SpotifyService.GetNextPage(page, AuthenticationService.AuthenticationToken);
                        }
                        else
                        {
                            page = null;
                        }
                    }while (page != null);

                    PlaylistTracks = tracks;
                }
                catch (Exception ex)
                {
                    PageException = ex;
                }

                NumberOfLoadedTracks = PlaylistTracks.Count();
                IsPlaylistLoading    = false;
                Stopwatch.Stop();

                StateHasChanged();
            }
            catch (Exception ex)
            {
                PageException = ex;
            }
        }