/// <summary>
 /// Plays the song.
 /// </summary>
 /// <param name="song">The song.</param>
 public async Task PlaySongAsync(YouTubeSong song)
 {           
     var url = await MT.YouTube.GetVideoUriAsync(song.SongId, MT.YouTubeQuality.QualityLow);
     this.CurrentUri = url.Uri;
     this.CurrentPlayedSong = song;
 }
        /// <summary>
        /// Updates the song position in playlist.
        /// </summary>
        /// <param name="userEmail">The user email.</param>
        /// <param name="songId">The song identifier.</param>
        /// <param name="playlistId">The playlist identifier.</param>
        /// <param name="position">The position.</param>
        /// <returns>is the song updated</returns>
        public bool UpdateSongPositionInPlaylist(
            string userEmail, 
            string playlistId,
            YouTubeSong song,
            int position)
        {
            bool isSuccessfullyUpdated = false;

            try
            {
                YouTubeServiceClient service = new YouTubeServiceClient();
                service.UpdatePlaylistItemAsync(userEmail, song.SongId, playlistId, song.PlayListItemId, position).Wait();
                isSuccessfullyUpdated = true;
            }
            catch (AggregateException ex)
            {
                foreach (var e in ex.InnerExceptions)
                {
                    //TODO: Add Logging
                    isSuccessfullyUpdated = false;
                }
            }

            return isSuccessfullyUpdated;
        }
        /// <summary>
        /// Gets the play list songs internal asynchronous.
        /// </summary>
        /// <param name="userEmail">The user email.</param>
        /// <param name="playListId">The play list identifier.</param>
        private async Task GetPlayListSongsInternalAsync(string userEmail, string playListId, List<IYouTubeSong> playListSongs)
        {
            var youtubeService = await this.GetYouTubeService(userEmail);

            var channelsListRequest = youtubeService.Channels.List("contentDetails");
            channelsListRequest.Mine = true;
            var nextPageToken = "";
            while (nextPageToken != null)
            {
                PlaylistItemsResource.ListRequest listRequest = youtubeService.PlaylistItems.List("contentDetails");
                listRequest.MaxResults = 50;
                listRequest.PlaylistId = playListId;
                listRequest.PageToken = nextPageToken;
                var response = await listRequest.ExecuteAsync();
                if (playListSongs == null)
                {
                    playListSongs = new List<IYouTubeSong>();
                }
                foreach (var playlistItem in response.Items)
                {
                    VideosResource.ListRequest videoR = youtubeService.Videos.List("snippet");
                    videoR.Id = playlistItem.ContentDetails.VideoId;
                    var responseV = await videoR.ExecuteAsync();
                    KeyValuePair<string, string> parsedSong = SongTitleParser.ParseTitle(responseV.Items[0].Snippet.Title);
                    IYouTubeSong currentSong = new YouTubeSong(parsedSong.Key, parsedSong.Value, responseV.Items[0].Id, playlistItem.Id, null);
                    playListSongs.Add(currentSong);
                    Debug.WriteLine(playlistItem.Snippet.Title);
                }
                nextPageToken = response.NextPageToken;
            }
        }
 /// <summary>
 /// Removes the song from playlist.
 /// </summary>
 /// <param name="song">The song.</param>
 public void RemoveSongFromPlaylist(YouTubeSong song)
 {
     YouTubeServiceClient.Instance.RemoveSongFromPlaylist(ExecutionContext.CurrentUser, song.PlayListItemId);
 }