From 8a6ada09669080d193236c254c64df463dc82f59 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=9A=93=E6=9C=88?= <353374337@qq.com>
Date: Sat, 6 Oct 2018 01:44:57 +0800
Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=8A=9F=E8=83=BD=EF=BC=88?=
=?UTF-8?q?=E5=BE=85=E7=BB=AD=EF=BC=89=E6=BA=9C=E4=BA=86=E6=BA=9C=E4=BA=86?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../HaoYue.CQTVShow.Hub/MainWindow.xaml | 19 ++-
.../HaoYue.CQTVShow.Hub/MainWindow.xaml.cs | 148 +++++++++++++++++-
.../HaoYue.CQTVShow.Hub/StaticClass.cs | 2 +-
3 files changed, 159 insertions(+), 10 deletions(-)
diff --git a/HaoYue.CQTVShow/HaoYue.CQTVShow.Hub/MainWindow.xaml b/HaoYue.CQTVShow/HaoYue.CQTVShow.Hub/MainWindow.xaml
index 63925da..3cec951 100644
--- a/HaoYue.CQTVShow/HaoYue.CQTVShow.Hub/MainWindow.xaml
+++ b/HaoYue.CQTVShow/HaoYue.CQTVShow.Hub/MainWindow.xaml
@@ -7,9 +7,11 @@
xmlns:controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
mc:Ignorable="d"
- Title="皓月云-重庆电视台本土节目播放器" Height="605" Width="823.5">
+ Title="皓月云-重庆电视台本土节目播放器" Height="621" Width="1039.5" Background="#FFFFFF">
-
+
@@ -19,9 +21,8 @@
-
+
-
@@ -37,8 +38,14 @@
-
-
+
+
+
+
+
diff --git a/HaoYue.CQTVShow/HaoYue.CQTVShow.Hub/MainWindow.xaml.cs b/HaoYue.CQTVShow/HaoYue.CQTVShow.Hub/MainWindow.xaml.cs
index b8d2c35..911decd 100644
--- a/HaoYue.CQTVShow/HaoYue.CQTVShow.Hub/MainWindow.xaml.cs
+++ b/HaoYue.CQTVShow/HaoYue.CQTVShow.Hub/MainWindow.xaml.cs
@@ -14,6 +14,8 @@ using System.Windows.Shapes;
//引用
using MahApps.Metro.Controls;
+using System.Threading;
+using System.IO;
namespace HaoYue.CQTVShow.Hub
{
@@ -25,6 +27,8 @@ namespace HaoYue.CQTVShow.Hub
public MainWindow()
{
InitializeComponent();
+ SetShowList(0);
+ this.BtnPlay.IsEnabled = false;
}
int frist = 1;
@@ -36,11 +40,149 @@ namespace HaoYue.CQTVShow.Hub
frist = 0;
return;
}
+ SetShowList(this.TabMeun.SelectedIndex);
+ }
- this.TabMeun.IsEnabled = false;
- HtmlDoIt.GetShowList(this.TabMeun.SelectedIndex, 1);
- this.TabMeun.IsEnabled = true;
+ private void SetShowList(int type)
+ {
+ ThreadPool.QueueUserWorkItem((obj) =>
+ {
+ this.LabelState.Dispatcher.BeginInvoke(new mystringsetter(SetLabelState), "正在获取...");
+ this.TabMeun.Dispatcher.BeginInvoke(new myboolsetter(SetTabMeunEnable), false);
+ try
+ {
+ HtmlDoIt.GetShowList(type, 1);
+ this.TabMeun.Dispatcher.BeginInvoke(new myvoidsetter(SetListBoxShow), null);
+ this.LabelState.Dispatcher.BeginInvoke(new mystringsetter(SetLabelState), "获取完毕~");
+
+ //切换后自动选择第一个
+ this.ListBoxShow.Dispatcher.BeginInvoke(new myintsetter(SetListBoxShowSelectIndex), 0);
+ }
+ catch
+ {
+ this.LabelState.Dispatcher.BeginInvoke(new mystringsetter(SetLabelState), "获取失败");
+ }
+ this.TabMeun.Dispatcher.BeginInvoke(new myboolsetter(SetTabMeunEnable), true);
+ }, null);
+ }
+
+
+ //一些类型委托
+ //public delegate void mydoublesetter(double value);
+ public delegate void myvoidsetter();
+ public delegate void myboolsetter(bool emmmmmmbool);
+ public delegate void myintsetter(int num);
+ public delegate void mystringsetter(string str);
+
+ public void SetListBoxShow()
+ {
this.ListBoxShow.ItemsSource = StaticClass.StaticShowList;
}
+
+ public void SetTabMeunEnable(bool set)
+ {
+ this.TabMeun.IsEnabled = set;
+ }
+
+ public void SetLabelState(string str)
+ {
+ this.LabelState.Content = str;
+ }
+
+ public void SetListBoxShowSelectIndex(int index)
+ {
+ this.ListBoxShow.SelectedIndex = index;
+ }
+
+ public void SetShowSelected(int index)
+ {
+ //BitmapImage image = new BitmapImage(new Uri(str, UriKind.Absolute));
+ byte[] btyarray = GetImageFromResponse(StaticClass.StaticShowList[index].ImageSrc, null);
+ MemoryStream ms = new MemoryStream(btyarray);
+ this.Image_SelectedShow.Source = BitmapFrame.Create(ms, BitmapCreateOptions.None, BitmapCacheOption.Default);
+ this.Label_SelectedName.Content = StaticClass.StaticShowList[index].Title;
+ this.Label_SelectedTime.Content = StaticClass.StaticShowList[index].Time;
+ StaticClass.PlayUrl = StaticClass.StaticShowList[index].ToPath;
+ this.BtnPlay.IsEnabled = true;
+ }
+
+
+ ///
+ /// 节目列表选择事件
+ ///
+ ///
+ ///
+ private void ListBoxSelectionChanged(object sender, SelectionChangedEventArgs e)
+ {
+ //获取选择的节目
+ int SelectedIndex = this.ListBoxShow.SelectedIndex;
+ ThreadPool.QueueUserWorkItem((obj) =>
+ {
+ this.Image_SelectedShow.Dispatcher.BeginInvoke(new myintsetter(SetShowSelected), SelectedIndex);
+ this.LabelState.Dispatcher.BeginInvoke(new mystringsetter(SetLabelState), "已选择第" + SelectedIndex + "个");
+ }, null);
+
+ }
+
+ #region 图片下载到流的处理
+ public static byte[] GetImageFromResponse(string url, string cookie = null)
+ {
+ redo:
+ try
+ {
+ System.Net.WebRequest request = System.Net.WebRequest.Create(url);
+ if (!string.IsNullOrWhiteSpace(cookie))
+ {
+ request.Headers[System.Net.HttpRequestHeader.Cookie] = cookie;
+ }
+
+
+ System.Net.WebResponse response = request.GetResponse();
+
+
+ using (Stream stream = response.GetResponseStream())
+ {
+ using (MemoryStream ms = new MemoryStream())
+ {
+ Byte[] buffer = new Byte[1024];
+ int current = 0;
+ do
+ {
+ ms.Write(buffer, 0, current);
+ } while ((current = stream.Read(buffer, 0, buffer.Length)) != 0);
+
+
+ //while ()
+ //{
+
+
+ //}
+ return ms.ToArray();
+ }
+ }
+ }
+ catch (System.Net.WebException ex)
+ {
+ if (ex.Message == "基础连接已经关闭: 发送时发生错误。")
+ {
+ goto redo;
+ }
+ else
+ {
+ throw;
+ }
+ }
+ }
+ #endregion
+
+ ///
+ /// 播放媒体时间
+ ///
+ ///
+ ///
+ private void PlayMedia(object sender, RoutedEventArgs e)
+ {
+ System.Diagnostics.Process.Start(StaticClass.PlayUrl);
+ }
}
}
diff --git a/HaoYue.CQTVShow/HaoYue.CQTVShow.Hub/StaticClass.cs b/HaoYue.CQTVShow/HaoYue.CQTVShow.Hub/StaticClass.cs
index 23b0073..803d07e 100644
--- a/HaoYue.CQTVShow/HaoYue.CQTVShow.Hub/StaticClass.cs
+++ b/HaoYue.CQTVShow/HaoYue.CQTVShow.Hub/StaticClass.cs
@@ -8,7 +8,7 @@ namespace HaoYue.CQTVShow.Hub
public class StaticClass
{
public static List StaticShowList = new List();
-
+ public static string PlayUrl = "";
}