public YouTubePage() { InitializeComponent(); this.DataContext = this; btnLowQuality.Background = new SolidColorBrush(Colors.Red); VideoQuality = YouTubeQuality.Quality480P; _viewModel = (CommentsViewModel)Resources["commentsViewModel"]; resultListBox.ItemRealized += resultListBox_ItemRealized; if (PhoneApplicationService.Current.State["YoutubeItem"] != null) { youtubeItem = PhoneApplicationService.Current.State["YoutubeItem"] as YoutubeItem; _pageNumber = 1; _viewModel.LoadPage(youtubeItem.CommentsLink, _pageNumber++); } }
private void ReadCallback(IAsyncResult asynchronousResult) { try { HttpWebRequest request = (HttpWebRequest)asynchronousResult.AsyncState; HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asynchronousResult); using (StreamReader reader = new StreamReader(response.GetResponseStream())) { XDocument xdoc = XDocument.Load(reader); XNamespace xmlns = "http://www.w3.org/2005/Atom"; XNamespace media = "http://search.yahoo.com/mrss/"; XNamespace gd = "http://schemas.google.com/g/2005"; XNamespace yt = "http://gdata.youtube.com/schemas/2007"; string commentsLink = ""; var items = xdoc.Root.Descendants("item").AsEnumerable(); YoutubeItem youTubeItem; Deployment.Current.Dispatcher.BeginInvoke(() => { foreach (var item in items) { var grp = item.Descendants(media + "group"); var ytNode = item.Descendants(yt + "statistics"); var ytRatingNode = item.Descendants(yt + "rating"); var comments = item.Descendants(gd + "comments"); if (comments.Count() > 0) commentsLink = comments.Descendants(gd + "feedLink").Attributes("href").First().Value; youTubeItem = new YoutubeItem { Title = grp.Elements(media + "title").First().Value, PlayerUrl = grp.Elements(media + "player").First().Attribute("url").Value, Description = grp.First().Value, ThumbNailUrl = new Uri(grp.Elements(media + "thumbnail").Select(u => (string)u.Attribute("url")).First()), ViewCount = ytNode.Attributes("viewCount").First().Value, CommentsLink = commentsLink }; if (ytRatingNode.Count() > 0) { youTubeItem.NumberOfLikes = ytRatingNode.Attributes("numLikes").First().Value; youTubeItem.NumberOfDisLikes = ytRatingNode.Attributes("numDislikes").First().Value; } YouTubeItemCollection.Add(youTubeItem); } IsLoading = false; }); } } catch (Exception e) { Deployment.Current.Dispatcher.BeginInvoke(() => { MessageBox.Show("Network error occured " + e.Message); }); } }
void webClient_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e) { if (e.Result != null) { var youtubeItemsList = new ObservableCollection<YoutubeItem>(); TextReader tr = new StringReader(e.Result ); XDocument xdoc = XDocument.Load(tr); XNamespace xmlns = "http://www.w3.org/2005/Atom"; XNamespace media = "http://search.yahoo.com/mrss/"; XNamespace gd = "http://schemas.google.com/g/2005"; XNamespace yt = "http://gdata.youtube.com/schemas/2007"; string commentsLink = ""; YoutubeItem youTubeItem; var items = xdoc.Root.Descendants("item").AsEnumerable(); foreach(var item in items){ var grp = item.Descendants(media + "group"); var ytNode = item.Descendants(yt + "statistics"); var comments = item.Descendants(gd + "comments"); var ytRatingNode = item.Descendants(yt + "rating"); if (comments.Count() > 0 ) commentsLink = comments.Descendants(gd + "feedLink").Attributes("href").First().Value; youTubeItem = new YoutubeItem { Title = grp.Elements(media + "title").First().Value, PlayerUrl = grp.Elements(media + "player").First().Attribute("url").Value, Description = grp.First().Value, ThumbNailUrl = new Uri(grp.Elements(media + "thumbnail").Select(u => (string)u.Attribute("url")).First()), ViewCount = ytNode.Attributes("viewCount").First().Value, CommentsLink = commentsLink }; if (ytRatingNode.Count() > 0) { youTubeItem.NumberOfLikes = ytRatingNode.Attributes("numLikes").First().Value; youTubeItem.NumberOfDisLikes = ytRatingNode.Attributes("numDislikes").First().Value; } youtubeItemsList.Add(youTubeItem); } listBox.ItemsSource = youtubeItemsList; } }