Ejemplo n.º 1
0
        private void CreateBlurredImage(ImageSource imageSource)
        {
            if (BlurredStrengh % 2 == 0 && BlurredStrengh != 0)
                throw new ArgumentException();

            if (ImageSource == null || _blurredImage == null) 
                return;

            var bitmapImage = ((BitmapSource)imageSource);
            if (bitmapImage.PixelHeight == 0)
                return;

            WriteableBitmap writeableBmp = new WriteableBitmap(bitmapImage);
            if (BlurredStrengh > 0)
                writeableBmp.BoxBlur(BlurredStrengh);

            _blurredImage.Source = writeableBmp;

            SetOverlaySize();
            _rootGrid.Opacity = 1;
        }
Ejemplo n.º 2
0
        private async Task <List <YoutubeVideo> > GetYoutubeChannel(string url)
        {
            try
            {
                var client  = new HttpClient();
                var feedXml = await client.GetStringAsync(new Uri(url));

                //var atomns = XNamespace.Get("http://www.w3.org/2005/Atom");
                var yt         = XNamespace.Get("http://gdata.youtube.com/schemas/2007");
                var openSearch = XNamespace.Get("http://a9.com/-/spec/opensearch/1.1/");
                var media      = XNamespace.Get("http://search.yahoo.com/mrss/");
                var gd         = XNamespace.Get("http://schemas.google.com/g/2005");

                var xml        = XElement.Parse(feedXml);
                var channel    = xml.Element("channel");
                var items      = channel.Elements("item");
                var videosList = new List <YoutubeVideo>();
                _totalResults = int.Parse(channel.Element(openSearch + "totalResults").Value);
                foreach (var item in items)
                {
                    var mediaGroup = item.Element(media + "group");
                    var video      = new YoutubeVideo
                    {
                        YoutubeLink = new Uri(item.Element("link").Value),
                        Title       = item.Element("title").Value,
                        PubDate     = DateTime.Parse(item.Element("pubDate").Value),
                        Duration    = new TimeSpan(0, 0, 0, (int)mediaGroup.Element(yt + "duration").Attribute("seconds")),
                        Likes       = (int)item.Element(yt + "rating").Attribute("numLikes"),
                        ViewCount   = (int)item.Element(yt + "statistics").Attribute("viewCount"),
                        Thumbnail   = new Uri(mediaGroup.Elements(media + "thumbnail").FirstOrDefault(o => o.Attribute(yt + "name").Value == "mqdefault").Attribute("url").Value),
                        Rating      = (float)item.Element(gd + "rating").Attribute("average")
                    };

                    var bm = new BitmapImage(video.Thumbnail)
                    {
                        CreateOptions = BitmapCreateOptions.None
                    };
                    bm.ImageOpened += (s, e) =>
                    {
                        if (video.BlurBgSource != null)
                        {
                            return;
                        }

                        var wb = new WriteableBitmap((BitmapImage)s);
                        wb.BoxBlur(23);
                        video.BlurBgSource = wb;
                        video.BlurBgSource.Invalidate();
                    };

                    var a = video.YoutubeLink.ToString().Remove(0, 31);
                    video.Id = a.Substring(0, 11);
                    videosList.Add(video);
                }
                return(videosList);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return(null);
            }
        }