コード例 #1
0
ファイル: LivePage.xaml.cs プロジェクト: Berrysoft/biliuwp
        public async void GetLiveInfo()
        {
            try
            {
                pr_Load.Visibility = Visibility.Visible;

                //gridview_SJ.ItemsSource=null;
                //gridview_DJ.Items.Clear();
                //gridview_FY.Items.Clear();
                //gridview_HH.Items.Clear();
                //gridview_JJ.Items.Clear();

                ////gridview_SH.Items.Clear();
                //gridview_WL.Items.Clear();
                //gridview_YZ.Items.Clear();
                //gridview_CW.Items.Clear();
                string url     = string.Format("http://live.bilibili.com/AppNewIndex/common?_device=android&platform=android&scale=xxhdpi");
                string results = await WebClientClass.GetResults_Live(new Uri(url));

                HomeLiveModel model = JsonConvert.DeserializeObject <HomeLiveModel>(results);
                if (model.code == 0)
                {
                    home_flipView.ItemsSource = model.data.banner;

                    model.data.partitions = model.data.partitions.OrderBy(x => x.partition.id).ToList();

                    this.DataContext = model.data;

                    //foreach (HomeLiveModel item in partModel)
                    //{
                    //    HomeLiveModel partitionModel = JsonConvert.DeserializeObject<HomeLiveModel>(item.partition.ToString());
                    //    List<HomeLiveModel> livesModel = JsonConvert.DeserializeObject<List<HomeLiveModel>>(item.lives.ToString());
                    //}
                    isLoaded = true;
                }
                else
                {
                    Utils.ShowMessageToast("读取直播失败" + model.message, 3000);
                    isLoaded = false;
                }
            }
            catch (Exception ex)
            {
                if (ex.HResult == -2147012867 || ex.HResult == -2147012889)
                {
                    Utils.ShowMessageToast("无法连接服务器,请检查你的网络连接", 3000);
                }
                else
                {
                    Utils.ShowMessageToast("读取直播失败" + ex.Message, 3000);
                }

                //ErrorEvent("读取直播失败" + ex.Message);
                isLoaded = false;
            }
            finally
            {
                pr_Load.Visibility = Visibility.Collapsed;
            }
        }
コード例 #2
0
        public async void GetLiveInfo()
        {
            try
            {
                pr_Load.Visibility = Visibility.Visible;

                //gridview_SJ.ItemsSource=null;
                //gridview_DJ.Items.Clear();
                //gridview_FY.Items.Clear();
                //gridview_HH.Items.Clear();
                //gridview_JJ.Items.Clear();

                ////gridview_SH.Items.Clear();
                //gridview_WL.Items.Clear();
                //gridview_YZ.Items.Clear();
                //gridview_CW.Items.Clear();
                string url     = string.Format("http://live.bilibili.com/AppNewIndex/common?_device=android&platform=android&scale=xxhdpi");
                string results = await WebClientClass.GetResults_Live(new Uri(url));

                HomeLiveModel model = JsonConvert.DeserializeObject <HomeLiveModel>(results);
                if (model.code == 0)
                {
                    HomeLiveModel        dataModel   = JsonConvert.DeserializeObject <HomeLiveModel>(model.data.ToString());
                    List <HomeLiveModel> bannerModel = JsonConvert.DeserializeObject <List <HomeLiveModel> >(dataModel.banner.ToString());
                    List <HomeLiveModel> partModel   = JsonConvert.DeserializeObject <List <HomeLiveModel> >(dataModel.partitions.ToString());
                    home_flipView.ItemsSource = bannerModel;
                    foreach (HomeLiveModel item in partModel)
                    {
                        HomeLiveModel        partitionModel = JsonConvert.DeserializeObject <HomeLiveModel>(item.partition.ToString());
                        List <HomeLiveModel> livesModel     = JsonConvert.DeserializeObject <List <HomeLiveModel> >(item.lives.ToString());
                        switch (partitionModel.name)
                        {
                        //case "热门直播":

                        //    //for (int i = 0; i < 12; i++)
                        //    //{
                        //    //    HomeLiveModel ownerModel = JsonConvert.DeserializeObject<HomeLiveModel>(livesModel[i].owner.ToString());
                        //    //    HomeLiveModel coverModel = JsonConvert.DeserializeObject<HomeLiveModel>(livesModel[i].cover.ToString());
                        //    //    livesModel[i].src = coverModel.src;
                        //    //    livesModel[i].name = ownerModel.name;
                        //    //    livesModel[i].mid = ownerModel.mid;
                        //    //    livesModel[i].face = ownerModel.face;
                        //    //    gridview_Hot.Items.Add(livesModel[i]);
                        //    //}
                        //    gridview_Hot.ItemsSource = livesModel;
                        //    break;
                        case "手机直播":
                            //for (int i = 0; i < livesModel.Count - 1; i++)
                            //{
                            //    HomeLiveModel ownerModel = JsonConvert.DeserializeObject<HomeLiveModel>(livesModel[i].owner.ToString());
                            //    HomeLiveModel coverModel = JsonConvert.DeserializeObject<HomeLiveModel>(livesModel[i].cover.ToString());
                            //    livesModel[i].src = coverModel.src;
                            //    livesModel[i].name = ownerModel.name;
                            //    livesModel[i].mid = ownerModel.mid;
                            //    livesModel[i].face = ownerModel.face;
                            //    gridview_SJ.Items.Add(livesModel[i]);
                            //}
                            gridview_SJ.ItemsSource = livesModel;
                            break;

                        case "唱见舞见":
                            //for (int i = 0; i < livesModel.Count - 1; i++)
                            //{
                            //    HomeLiveModel ownerModel = JsonConvert.DeserializeObject<HomeLiveModel>(livesModel[i].owner.ToString());
                            //    HomeLiveModel coverModel = JsonConvert.DeserializeObject<HomeLiveModel>(livesModel[i].cover.ToString());
                            //    livesModel[i].src = coverModel.src;
                            //    livesModel[i].name = ownerModel.name;
                            //    livesModel[i].mid = ownerModel.mid;
                            //    livesModel[i].face = ownerModel.face;
                            //    gridview_CW.Items.Add(livesModel[i]);
                            //}
                            gridview_CW.ItemsSource = livesModel;
                            break;

                        //case "萌宅推荐":
                        //    //for (int i = 0; i < livesModel.Count - 1; i++)
                        //    //{
                        //    //    HomeLiveModel ownerModel = JsonConvert.DeserializeObject<HomeLiveModel>(livesModel[i].owner.ToString());
                        //    //    HomeLiveModel coverModel = JsonConvert.DeserializeObject<HomeLiveModel>(livesModel[i].cover.ToString());
                        //    //    livesModel[i].src = coverModel.src;
                        //    //    livesModel[i].name = ownerModel.name;
                        //    //    livesModel[i].mid = ownerModel.mid;
                        //    //    livesModel[i].face = ownerModel.face;
                        //    //    gridview_MZ.Items.Add(livesModel[i]);
                        //    //}
                        //    gridview_MZ.ItemsSource = livesModel;
                        //    break;
                        case "绘画专区":
                            //for (int i = 0; i < livesModel.Count-1; i++)
                            //{
                            //    HomeLiveModel ownerModel = JsonConvert.DeserializeObject<HomeLiveModel>(livesModel[i].owner.ToString());
                            //    HomeLiveModel coverModel = JsonConvert.DeserializeObject<HomeLiveModel>(livesModel[i].cover.ToString());
                            //    livesModel[i].src = coverModel.src;
                            //    livesModel[i].name = ownerModel.name;
                            //    livesModel[i].mid = ownerModel.mid;
                            //    livesModel[i].face = ownerModel.face;
                            //    gridview_HH.Items.Add(livesModel[i]);
                            //}
                            gridview_HH.ItemsSource = livesModel;
                            break;

                        case "御宅文化":
                            //for (int i = 0; i < 12; i++)
                            //{
                            //    HomeLiveModel ownerModel = JsonConvert.DeserializeObject<HomeLiveModel>(livesModel[i].owner.ToString());
                            //    HomeLiveModel coverModel = JsonConvert.DeserializeObject<HomeLiveModel>(livesModel[i].cover.ToString());
                            //    livesModel[i].src = coverModel.src;
                            //    livesModel[i].name = ownerModel.name;
                            //    livesModel[i].mid = ownerModel.mid;
                            //    livesModel[i].face = ownerModel.face;
                            //    gridview_YZ.Items.Add(livesModel[i]);
                            //}
                            gridview_YZ.ItemsSource = livesModel;
                            break;

                        case "单机联机":
                            //for (int i = 0; i < 12; i++)
                            //{
                            //    HomeLiveModel ownerModel = JsonConvert.DeserializeObject<HomeLiveModel>(livesModel[i].owner.ToString());
                            //    HomeLiveModel coverModel = JsonConvert.DeserializeObject<HomeLiveModel>(livesModel[i].cover.ToString());
                            //    livesModel[i].src = coverModel.src;
                            //    livesModel[i].name = ownerModel.name;
                            //    livesModel[i].mid = ownerModel.mid;
                            //    livesModel[i].face = ownerModel.face;
                            //    gridview_DJ.Items.Add(livesModel[i]);
                            //}
                            gridview_DJ.ItemsSource = livesModel;
                            break;

                        case "网络游戏":
                            //for (int i = 0; i < 12; i++)
                            //{
                            //    HomeLiveModel ownerModel = JsonConvert.DeserializeObject<HomeLiveModel>(livesModel[i].owner.ToString());
                            //    HomeLiveModel coverModel = JsonConvert.DeserializeObject<HomeLiveModel>(livesModel[i].cover.ToString());
                            //    livesModel[i].src = coverModel.src;
                            //    livesModel[i].name = ownerModel.name;
                            //    livesModel[i].mid = ownerModel.mid;
                            //    livesModel[i].face = ownerModel.face;
                            //    gridview_WL.Items.Add(livesModel[i]);
                            //}
                            gridview_WL.ItemsSource = livesModel;
                            break;

                        case "电子竞技":
                            //for (int i = 0; i < 12; i++)
                            //{
                            //    HomeLiveModel ownerModel = JsonConvert.DeserializeObject<HomeLiveModel>(livesModel[i].owner.ToString());
                            //    HomeLiveModel coverModel = JsonConvert.DeserializeObject<HomeLiveModel>(livesModel[i].cover.ToString());
                            //    livesModel[i].src = coverModel.src;
                            //    livesModel[i].name = ownerModel.name;
                            //    livesModel[i].mid = ownerModel.mid;
                            //    livesModel[i].face = ownerModel.face;
                            //    gridview_JJ.Items.Add(livesModel[i]);
                            //}
                            gridview_JJ.ItemsSource = livesModel;
                            break;

                        case "放映厅":
                            //for (int i = 0; i < 12; i++)
                            //{
                            //    HomeLiveModel ownerModel = JsonConvert.DeserializeObject<HomeLiveModel>(livesModel[i].owner.ToString());
                            //    HomeLiveModel coverModel = JsonConvert.DeserializeObject<HomeLiveModel>(livesModel[i].cover.ToString());
                            //    livesModel[i].src = coverModel.src;
                            //    livesModel[i].name = ownerModel.name;
                            //    livesModel[i].mid = ownerModel.mid;
                            //    livesModel[i].face = ownerModel.face;
                            //    gridview_FY.Items.Add(livesModel[i]);
                            //}
                            gridview_FY.ItemsSource = livesModel;
                            break;

                        default:
                            break;
                        }
                    }
                    isLoaded = true;
                }
                else
                {
                    messShow.Show("读取直播失败" + model.message, 3000);
                    isLoaded = false;
                }
            }
            catch (Exception ex)
            {
                if (ex.HResult == -2147012867 || ex.HResult == -2147012889)
                {
                    messShow.Show("无法连接服务器,请检查你的网络连接", 3000);
                }
                else
                {
                    messShow.Show("读取直播失败" + ex.Message, 3000);
                }

                //ErrorEvent("读取直播失败" + ex.Message);
                isLoaded = false;
            }
            finally
            {
                pr_Load.Visibility = Visibility.Collapsed;
            }
        }