Beispiel #1
0
        public List <Button> btns       = new List <Button>(); //初始化
        public GridView createGridView(PlayList playList)      //单独创建一个名为我的收藏的gridview,返回值为这个gridview
        {
            grid = new GridView();
            grid.HorizontalAlignment = HorizontalAlignment.Center;
            PivotItem pi1 = new PivotItem
            {
                Header  = playList.Name,
                Content = grid
            };

            mainpage_pivot.Items.Add(pi1);
            grid.IsItemClickEnabled = true;
            grid.ItemClick         += new ItemClickEventHandler((sender, arg) => {
                Live live = (Live)((StackPanel)arg.ClickedItem).Tag;
                //Debug.WriteLine(live.Name);
                root.Navigate(typeof(PlayerPage), live);
                Debug.WriteLine(live.GetSimpleName());
            });
            return(grid);
        }
Beispiel #2
0
        //添加一个pivot页面
        public void AddItem(PlayList playList)
        {
            GridView g = new GridView();

            g.HorizontalAlignment = HorizontalAlignment.Center;

            PivotItem pi1 = new PivotItem
            {
                Header  = playList.Name,
                Content = g
            };

            mainpage_pivot.Items.Add(pi1);
            foreach (Live obj in playList.Livelist)
            {
                TextBlock t = new TextBlock
                {
                    Text                = obj.Name,
                    FontSize            = 24,
                    HorizontalAlignment = HorizontalAlignment.Center,
                };


                Button b = new Button
                {
                    Content             = "\xE006",
                    FontSize            = 24,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    Tag        = obj,
                    Background = new SolidColorBrush(Color.FromArgb(255, 255, 255, 255)),
                    FontFamily = font,
                    Width      = 50,
                    Height     = 50,
                    Foreground = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0))
                };
                b.Name   = obj.Name;       //方便查找相应的btn
                b.Click += MainPage_Click; //主界面的点击事件
                btns.Add(b);               //将主界面的每个btn都加到列表里


                Image img = new Image
                {
                    Source = new BitmapImage(new Uri("https://hdtv.neu6.edu.cn/wall/img/" + obj.GetSimpleName() + "_s.png")),
                    //TODO 可以换一种更睿智的方法,目前显示效果不够好
                    //高清频道和非高清频道图片分辨率不同,手动设置图片宽高
                    //否则非高清频道 textblock无法显示
                    Width  = 300,
                    Height = 225
                };


                bool a = false;
                foreach (Live live1 in playList1.Livelist)
                {
                    if (obj.Name == live1.Name)
                    {
                        a = true;
                    }
                }
                if (a)
                {
                    b.Content = "\xE00B";
                }                               //初始化主界面button的值

                StackPanel itemPanel = new StackPanel();
                itemPanel.Margin = new Thickness(8);
                itemPanel.Children.Add(img);
                itemPanel.Children.Add(t);
                itemPanel.Children.Add(b);
                itemPanel.Tag = obj;
                g.Items.Add(itemPanel);
            }



            g.IsItemClickEnabled = true;
            g.ItemClick         += new ItemClickEventHandler((sender, arg) => {
                Live live = (Live)((StackPanel)arg.ClickedItem).Tag;
                //Debug.WriteLine(live.Name);
                root.Navigate(typeof(PlayerPage), live);
            });
        }
Beispiel #3
0
        // https://docs.microsoft.com/zh-cn/uwp/api/windows.storage.pickers.fileopenpicker#examples

        public async Task Gets(Uri uri)
        {
            try
            {
                HttpClient httpClient = new HttpClient();
                var        response   = await httpClient.GetAsync(uri);

                var buffer = await response.Content.ReadAsBufferAsync();

                //转为UTF-8格式
                DataReader reader      = DataReader.FromBuffer(buffer);
                byte[]     fileContent = new byte[reader.UnconsumedBufferLength];
                reader.ReadBytes(fileContent);
                Encoding encoding = Encoding.GetEncoding("UTF-8");
                var      str      = encoding.GetString(fileContent);

                JsonObject jsonObject = JsonObject.Parse(str);
                JsonArray  types      = jsonObject["type"].GetArray();
                JsonArray  lives      = jsonObject["live"].GetArray();

                //储存节目单
                Dictionary <String, PlayList> listMap = new Dictionary <string, PlayList>();

                foreach (JsonValue obj in types)
                {
                    String name = obj.GetObject()["name"].GetString();
                    String uid  = obj.GetObject()["id"].GetString();
                    listMap.Add(uid, new PlayList(name, uid));
                }

                // Live json格式
                // "num":50001,
                // "itemid":"uid0",
                // "name":"CCTV-1高清",
                // "urllist":"http:....."

                foreach (JsonValue obj in lives)
                {
                    String name    = obj.GetObject()["name"].GetString();
                    String itemid  = obj.GetObject()["itemid"].GetString();
                    String urllist = obj.GetObject()["urllist"].GetString();
                    listMap[itemid].AddLive(new Live(urllist, name, itemid));
                }


                GridView    grid       = this.createGridView(playList1);//创建我的收藏的gridview
                StorageFile sampleFile = await localFolder.CreateFileAsync("dataFile.txt", CreationCollisionOption.OpenIfExists);

                String timestamp = await FileIO.ReadTextAsync(sampleFile);

                string[] Array = timestamp.Split(new char[] { '+' });
                for (int i = 1; i < Array.Length - 2; i = i + 3)
                {
                    Live live = new Live(Array[i], Array[i + 1], Array[i + 2]);
                    playList1.AddLive(live);
                    AddLivesToPivot(grid, live);
                } //把我的收藏里面的频道加到gridview里


                //添加到页面
                foreach (KeyValuePair <String, PlayList> pair in listMap)
                {
                    PlayList playList = pair.Value;
                    this.AddItem(playList);
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine("xxxxx{0}", e);
                button_open.Visibility = Visibility.Visible;
            }
            finally
            {
                mainpage_progress_ring.IsActive = false;
            }
        }