private async Task LoadPlaylistInfoInternal(string playlistid) { PlaylistItems.Clear(); string pagination = null; string firstpagination = null; // Loop through 4 times to load this completely at least // due to YouTube's 50 result restriction // Max playlist restriction = 200 video anyway for (int i = 0; i < 4; i++) { IList <Google.Apis.YouTube.v3.Data.PlaylistItem> collection = null; // Load playlist var videoInfoRequest = YoutubeService.service.PlaylistItems.List("contentDetails,id,status,snippet"); videoInfoRequest.PlaylistId = playlistid; videoInfoRequest.MaxResults = 50; if (pagination != null) { videoInfoRequest.PageToken = pagination; } try { var videoResultResponse = await videoInfoRequest.ExecuteAsync(); // Set new pagination pagination = videoResultResponse.NextPageToken; if (firstpagination == null) { firstpagination = pagination; // no choice, we might load the first at the end again.. there's no pagination information for the first page } else if (firstpagination == pagination) { break; } collection = videoResultResponse.Items; } catch { } // Add it to new collection if (collection != null) { foreach (Google.Apis.YouTube.v3.Data.PlaylistItem item in collection) { // item.Snippet.ur PlaylistItems.Add(item); } } } // Update playlist item count PlaylistItemsCount = _PlaylistItems.Count; }
public void LoadState(string parameter, Dictionary <string, object> statePageState) { if (!statePageState.ContainsKey(StatePlaylistKey) || PlaylistItems.Any()) { return; } var bytes = Convert.FromBase64String((string)statePageState[StatePlaylistKey]); var memoryStream = new MemoryStream(bytes); var xmlSerializer = new XmlSerializer(typeof(PlaylistItemCollection)); var playlist = (PlaylistItemCollection)xmlSerializer.Deserialize(memoryStream); PlaylistItems.Clear(); PlaylistItems.AddRange(playlist); }
/// <summary> /// Clears the playlist /// </summary> public void ClearPlaylist() { PlaylistItems.Clear(); }