/// <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>
        /// 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);
        }
Пример #3
0
        /// <summary>
        /// Handles the Click event of the btnDelete control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RoutedEventArgs"/> instance containing the event data.</param>
        private void btnDelete_Click(object sender, RoutedEventArgs e)
        {
            YouTubeSong songForDeletion = ((FrameworkElement)sender).DataContext as YouTubeSong;

            this.YouTubePlaylistsEditViewModel.ObservableSongs.Remove(songForDeletion);
            this.YouTubePlaylistsEditViewModel.RemoveSongFromPlaylist(songForDeletion);
        }
        /// <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>
        /// Gets the next song to be played.
        /// </summary>
        /// <returns>the next song to be played</returns>
        private YouTubeSong GetNextSongToBePlayed()
        {
            YouTubeSong nextSongToBePlayed = null;

            if (this.ObservableQueueSongs.Count > 0)
            {
                nextSongToBePlayed = this.ObservableQueueSongs.First();
                this.AddSongsToBeRemovedFromQueueToRegistry(new List <YouTubeSong> {
                    nextSongToBePlayed
                });
            }
            else
            {
                int currentSongIndex = this.ObservableOriginalSongs.IndexOf(this.CurrentPlayedSong);
                int nextIndex        = 0;
                if (this.ObservableOriginalSongs.Count - 1 > currentSongIndex)
                {
                    nextIndex = currentSongIndex + 1;
                }
                nextSongToBePlayed = this.ObservableOriginalSongs[nextIndex];
            }

            return(nextSongToBePlayed);
        }
Пример #6
0
 /// <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);
 }
        /// <summary>
        /// Plays the next song asynchronous.
        /// </summary>
        /// <returns>the play next song task</returns>
        public async Task PlayNextSongAsync()
        {
            YouTubeSong nextSong = this.GetNextSongToBePlayed();

            await this.PlaySongAsync(nextSong);
        }