From 4e627d28019967cd6724dcef8bdb253aa280950b 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 15:45:19 +0800
Subject: [PATCH] =?UTF-8?q?=E5=88=9D=E6=AD=A5=E5=AE=8C=E5=96=84?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../HaoYue.CQTVShow.Hub.csproj | 4 +
.../HaoYue.CQTVShow.Hub/HtmlDoIt.cs | 45 ++---
.../HaoYue.CQTVShow.Hub/MainWindow.xaml | 24 ++-
.../HaoYue.CQTVShow.Hub/MainWindow.xaml.cs | 66 +++++++-
.../HaoYue.CQTVShow.Hub/StartOtherProgarm.cs | 159 ++++++++++++++++++
.../HaoYue.CQTVShow.Hub/StaticClass.cs | 1 +
6 files changed, 268 insertions(+), 31 deletions(-)
create mode 100644 HaoYue.CQTVShow/HaoYue.CQTVShow.Hub/StartOtherProgarm.cs
diff --git a/HaoYue.CQTVShow/HaoYue.CQTVShow.Hub/HaoYue.CQTVShow.Hub.csproj b/HaoYue.CQTVShow/HaoYue.CQTVShow.Hub/HaoYue.CQTVShow.Hub.csproj
index 78509c1..21282bd 100644
--- a/HaoYue.CQTVShow/HaoYue.CQTVShow.Hub/HaoYue.CQTVShow.Hub.csproj
+++ b/HaoYue.CQTVShow/HaoYue.CQTVShow.Hub/HaoYue.CQTVShow.Hub.csproj
@@ -64,6 +64,7 @@
MSBuild:Compile
Designer
+
MSBuild:Compile
@@ -103,5 +104,8 @@
Settings.Designer.cs
+
+
+
\ No newline at end of file
diff --git a/HaoYue.CQTVShow/HaoYue.CQTVShow.Hub/HtmlDoIt.cs b/HaoYue.CQTVShow/HaoYue.CQTVShow.Hub/HtmlDoIt.cs
index 7dd5dda..53c36e1 100644
--- a/HaoYue.CQTVShow/HaoYue.CQTVShow.Hub/HtmlDoIt.cs
+++ b/HaoYue.CQTVShow/HaoYue.CQTVShow.Hub/HtmlDoIt.cs
@@ -11,7 +11,7 @@ namespace HaoYue.CQTVShow.Hub
{
public static class HtmlDoIt
{
- public static string GetShowList(int type,int pageindex)
+ public static bool GetShowList(int type,int pageindex)
{
string url = "";
if (type == 0)
@@ -36,31 +36,38 @@ namespace HaoYue.CQTVShow.Hub
}
HtmlWeb htmlweb = new HtmlWeb();
- HtmlDocument htmldoc = htmlweb.Load(url);
- HtmlNodeCollection hnc = htmldoc.DocumentNode.SelectNodes("//div[@class='main']/ul/li");
-
- StaticClass.StaticShowList = new List();
- //这个下标貌似是从1开始的
- for (int i = 1; i <= hnc.Count; i++)
+ try
{
+ HtmlDocument htmldoc = htmlweb.Load(url);
+ HtmlNodeCollection hnc = htmldoc.DocumentNode.SelectNodes("//div[@class='main']/ul/li");
- if (htmldoc.DocumentNode.SelectNodes("//div[@class='main']/ul/li[" + i + "]") != null)
+ StaticClass.StaticShowList = new List();
+ //这个下标貌似是从1开始的
+ for (int i = 1; i <= hnc.Count; i++)
{
- StaticShow ss = new StaticShow();
- ss.Title = htmldoc.DocumentNode.SelectNodes("//div[@class='main']/ul/li[" + i + "]/a")[0].Attributes["Title"].Value;
- ss.ToPath = htmldoc.DocumentNode.SelectNodes("//div[@class='main']/ul/li[" + i + "]/a")[0].Attributes["href"].Value;
- //取值
- ss.Time = htmldoc.DocumentNode.SelectNodes("//div[@class='main']/ul/li[" + i + "]/a/div/span")[0].InnerHtml;
- //读取img标签的src
- ss.ImageSrc = htmldoc.DocumentNode.SelectNodes("//div[@class='main']/ul/li[" + i + "]/a/div/img")[0].Attributes["src"].Value;
+ if (htmldoc.DocumentNode.SelectNodes("//div[@class='main']/ul/li[" + i + "]") != null)
+ {
+ StaticShow ss = new StaticShow();
+ ss.Title = htmldoc.DocumentNode.SelectNodes("//div[@class='main']/ul/li[" + i + "]/a")[0].Attributes["Title"].Value;
+
+ ss.ToPath = htmldoc.DocumentNode.SelectNodes("//div[@class='main']/ul/li[" + i + "]/a")[0].Attributes["href"].Value;
+ //取值
+ ss.Time = htmldoc.DocumentNode.SelectNodes("//div[@class='main']/ul/li[" + i + "]/a/div/span")[0].InnerHtml;
+ //读取img标签的src
+ ss.ImageSrc = htmldoc.DocumentNode.SelectNodes("//div[@class='main']/ul/li[" + i + "]/a/div/img")[0].Attributes["src"].Value;
+
+ StaticClass.StaticShowList.Add(ss);
+ }
- StaticClass.StaticShowList.Add(ss);
}
-
+ return true;
+ }
+ catch
+ {
+ return false;
}
- return "";
}
public static ShowInfo GetShowInfo(string url)
@@ -90,7 +97,7 @@ namespace HaoYue.CQTVShow.Hub
var hdm3u8 = list.Where(w => w.filetype == 1 && w.Path.Contains("b5000")).FirstOrDefault();
if (hdm3u8 != null)
{
- si.PlayNormalM3u8Url = si.PlayListM3u8Url.Substring(0, si.PlayListM3u8Url.LastIndexOf("/")+1) + normalm3u8.Path;
+ si.PlayHDM3u8Url = si.PlayListM3u8Url.Substring(0, si.PlayListM3u8Url.LastIndexOf("/")+1) + hdm3u8.Path;
}
return si;
diff --git a/HaoYue.CQTVShow/HaoYue.CQTVShow.Hub/MainWindow.xaml b/HaoYue.CQTVShow/HaoYue.CQTVShow.Hub/MainWindow.xaml
index cd74292..7989794 100644
--- a/HaoYue.CQTVShow/HaoYue.CQTVShow.Hub/MainWindow.xaml
+++ b/HaoYue.CQTVShow/HaoYue.CQTVShow.Hub/MainWindow.xaml
@@ -7,9 +7,15 @@
xmlns:controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
mc:Ignorable="d"
- Title="皓月云-重庆电视台本土节目播放器" Height="621" Width="1039.5" Background="#FFFFFF">
+ Title="皓月云-重庆电视台本土节目播放器 0.1.0 预览版" Height="645" Width="765.5"
+
+ MaxHeight="645" MaxWidth="765.5"
+ MinHeight="645" MinWidth="765.5"
+ Background="#FFFFFF">
-
@@ -38,7 +44,7 @@
-
+
-
+
+
+
+
+
+
diff --git a/HaoYue.CQTVShow/HaoYue.CQTVShow.Hub/MainWindow.xaml.cs b/HaoYue.CQTVShow/HaoYue.CQTVShow.Hub/MainWindow.xaml.cs
index 2159c16..58353a0 100644
--- a/HaoYue.CQTVShow/HaoYue.CQTVShow.Hub/MainWindow.xaml.cs
+++ b/HaoYue.CQTVShow/HaoYue.CQTVShow.Hub/MainWindow.xaml.cs
@@ -16,6 +16,8 @@ using System.Windows.Shapes;
using MahApps.Metro.Controls;
using System.Threading;
using System.IO;
+using System.Diagnostics;
+using MahApps.Metro.Controls.Dialogs;
namespace HaoYue.CQTVShow.Hub
{
@@ -29,6 +31,7 @@ namespace HaoYue.CQTVShow.Hub
InitializeComponent();
SetShowList(0);
this.BtnPlay.IsEnabled = false;
+ this.ShowMessageAsync("欢迎使用\n皓月云-重庆本土节目播放器\nver 0.1.0 预览版", "本软件目的是给重庆本土电视节目爱好者,\n一个便捷的节目选择器,便捷的观看体验\n节目来源和版权均归 重庆网络广播电视台 所有\n\n请在节目列表选择要观看的栏目", MessageDialogStyle.Affirmative, new MetroDialogSettings() { AffirmativeButtonText = "确定" });
}
int frist = 1;
@@ -40,6 +43,8 @@ namespace HaoYue.CQTVShow.Hub
frist = 0;
return;
}
+
+ StaticClass.IndexPage = 1;
SetShowList(this.TabMeun.SelectedIndex);
}
@@ -51,12 +56,17 @@ namespace HaoYue.CQTVShow.Hub
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);
+ if (HtmlDoIt.GetShowList(type, StaticClass.IndexPage))
+ {
+ this.TabMeun.Dispatcher.BeginInvoke(new myvoidsetter(SetListBoxShow), null);
+ this.LabelState.Dispatcher.BeginInvoke(new mystringsetter(SetLabelState), "获取完毕~");
+ //切换后自动选择第一个
+ this.ListBoxShow.Dispatcher.BeginInvoke(new myintsetter(SetListBoxShowSelectIndex), 0);
+ }
+ else
+ {
+ this.LabelState.Dispatcher.BeginInvoke(new mystringsetter(SetLabelState), "获取失败");
+ }
}
catch
{
@@ -77,6 +87,13 @@ namespace HaoYue.CQTVShow.Hub
public void SetListBoxShow()
{
this.ListBoxShow.ItemsSource = StaticClass.StaticShowList;
+ this.TextPageIndex.Text = StaticClass.IndexPage.ToString();
+ if (StaticClass.IndexPage > 1)
+ {
+ this.Btn_UpPage.IsEnabled = true;
+ }
+ else
+ this.Btn_UpPage.IsEnabled = false;
}
public void SetTabMeunEnable(bool set)
@@ -104,6 +121,7 @@ namespace HaoYue.CQTVShow.Hub
this.Label_SelectedTime.Content = StaticClass.StaticShowList[index].Time;
StaticClass.PlayUrl = StaticClass.StaticShowList[index].ToPath;
this.BtnPlay.IsEnabled = true;
+ this.BtnDown.IsEnabled = true;
}
@@ -124,7 +142,7 @@ namespace HaoYue.CQTVShow.Hub
ThreadPool.QueueUserWorkItem((obj) =>
{
this.Image_SelectedShow.Dispatcher.BeginInvoke(new myintsetter(SetShowSelected), SelectedIndex);
- this.LabelState.Dispatcher.BeginInvoke(new mystringsetter(SetLabelState), "已选择第" + SelectedIndex + "个");
+ //this.LabelState.Dispatcher.BeginInvoke(new mystringsetter(SetLabelState), "已选择第" + SelectedIndex + "个");
}, null);
}
@@ -189,6 +207,40 @@ namespace HaoYue.CQTVShow.Hub
{
//System.Diagnostics.Process.Start(StaticClass.PlayUrl);
StaticClass.StaticShowInfo = HtmlDoIt.GetShowInfo(StaticClass.PlayUrl);
+
+ string playm3u8url;
+ if (StaticClass.StaticShowInfo.PlayHDM3u8Url != null)
+ playm3u8url = StaticClass.StaticShowInfo.PlayHDM3u8Url;
+ else
+ playm3u8url = StaticClass.StaticShowInfo.PlayNormalM3u8Url;
+
+ if (playm3u8url == null)
+ this.ShowMessageAsync("错误", "视频资源有误", MessageDialogStyle.Affirmative, new MetroDialogSettings() { AffirmativeButtonText = "确定" });
+
+ Process myprocess = new Process();
+ ProcessStartInfo startInfo = new ProcessStartInfo(Environment.CurrentDirectory + @"\\PotPlayer\\PotPlayerMini.exe", StaticClass.StaticShowInfo.PlayHDM3u8Url);
+ myprocess.StartInfo = startInfo;
+ myprocess.StartInfo.UseShellExecute = false;
+ myprocess.Start();
+
+
+ }
+
+ private void NextPage(object sender, RoutedEventArgs e)
+ {
+ StaticClass.IndexPage = Convert.ToInt32(this.TextPageIndex.Text) + 1;
+ SetShowList(this.TabMeun.SelectedIndex);
+ }
+
+ private void UpPage(object sender, RoutedEventArgs e)
+ {
+ StaticClass.IndexPage = Convert.ToInt32(this.TextPageIndex.Text) - 1;
+ SetShowList(this.TabMeun.SelectedIndex);
+ }
+
+ private void DownLoadClicked(object sender, RoutedEventArgs e)
+ {
+ this.ShowMessageAsync("喵喵喵", "下载功能暂时没有做呢", MessageDialogStyle.Affirmative, new MetroDialogSettings() { AffirmativeButtonText = "确定" });
}
}
}
diff --git a/HaoYue.CQTVShow/HaoYue.CQTVShow.Hub/StartOtherProgarm.cs b/HaoYue.CQTVShow/HaoYue.CQTVShow.Hub/StartOtherProgarm.cs
new file mode 100644
index 0000000..fa1dc8c
--- /dev/null
+++ b/HaoYue.CQTVShow/HaoYue.CQTVShow.Hub/StartOtherProgarm.cs
@@ -0,0 +1,159 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.InteropServices;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Interop;
+
+namespace HaoYue.CQTVShow.Hub
+{
+ class EmbeddedApp : HwndHost, IKeyboardInputSink
+ {
+ [DllImport("user32.dll")]
+ private static extern int SetParent(IntPtr hWndChild, IntPtr hWndParent);
+ [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
+ private static extern uint SetWindowLong(IntPtr hwnd, int nIndex, uint newLong);
+ [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
+ private static extern uint GetWindowLong(IntPtr hwnd, int nIndex);
+ [DllImport("user32.dll")]
+ private static extern int EnumWindows(CallBackPtr callPtr, ref WindowInfo WndInfoRef);
+ [DllImport("User32.dll")]
+ static extern int GetWindowText(IntPtr handle, StringBuilder text, int MaxLen);
+ [DllImport("user32.dll")]
+ public static extern int GetWindowRect(IntPtr hwnd, ref RECT rc);
+ [DllImport("user32.dll", EntryPoint = "SendMessage", SetLastError = true, CharSet = CharSet.Auto)]
+ private static extern int SendMessage(IntPtr hwnd, uint wMsg, int wParam, int lParam); //对外部软件窗口发送一些消息(如 窗口最大化、最小化等)
+ internal const int
+ GWL_WNDPROC = (-4),
+ GWL_HINSTANCE = (-6),
+ GWL_HWNDPARENT = (-8),
+ GWL_STYLE = (-16),
+ GWL_EXSTYLE = (-20),
+ GWL_USERDATA = (-21),
+ GWL_ID = (-12);
+ internal const uint
+ WS_CHILD = 0x40000000,
+ WS_VISIBLE = 0x10000000,
+ LBS_NOTIFY = 0x00000001,
+ HOST_ID = 0x00000002,
+ LISTBOX_ID = 0x00000001,
+ WS_VSCROLL = 0x00200000,
+ WS_BORDER = 0x00800000,
+ WS_POPUP = 0x80000000;
+ private const int HWND_TOP = 0x0;
+ private const int WM_COMMAND = 0x0112;
+ private const int WM_QT_PAINT = 0xC2DC;
+ private const int WM_PAINT = 0x000F;
+ private const int WM_SIZE = 0x0005;
+ private const int SWP_FRAMECHANGED = 0x0020;
+ private const int WM_SYSCOMMAND = 0x0112;
+ private const int SC_CLOSE = 0xF060;
+ private const int SC_MINIMIZE = 0xF020;
+ private const int SC_MAXIMIZE = 0xF030;
+ private const uint WM_LBUTTONDOWN = 0x0201;
+ private const uint WM_LBUTTONUP = 0x0202;
+ private const int BM_CLICK = 0xF5;
+
+ private Border WndHoster;
+ private double screenW, screenH;
+ private System.Diagnostics.Process appProc;
+ private uint oldStyle;
+ public IntPtr hwndHost;
+ private String appPath;
+ public EmbeddedApp(Border b, double sW, double sH, String p, String f)
+ {
+ WndHoster = b;
+ screenH = sH;
+ screenW = sW;
+ appPath = p;
+ WinInfo = new WindowInfo();
+ WinInfo.winTitle = f;
+ }
+ protected override HandleRef BuildWindowCore(HandleRef hwndParent)
+ {
+ hwndHost = FindTheWindow();
+ //if (hwndHost == null)
+ //{
+ appProc = new System.Diagnostics.Process();
+ appProc.StartInfo.FileName = appPath;
+ appProc.Start();
+ Thread.Sleep(5000);
+ hwndHost = FindTheWindow();
+ SendMessage(hwndHost, WM_SYSCOMMAND, SC_MINIMIZE, 0);
+ //}
+ // 嵌入在HwnHost中的窗口必须要 设置为WS_CHILD风格
+ oldStyle = GetWindowLong(hwndHost, GWL_STYLE);
+ uint newStyle = oldStyle;
+ //WS_CHILD和WS_POPUP不能同时存在。有些Win32窗口,比如QQ的窗口,有WS_POPUP属性,这样嵌入的时候会导致程序错误
+ newStyle |= WS_CHILD;
+ newStyle &= ~WS_POPUP;
+ newStyle &= ~WS_BORDER;
+ SetWindowLong(hwndHost, GWL_STYLE, newStyle);
+ //将窗口居中,实际上是将窗口的容器居中
+ RePosWindow(WndHoster, WndHoster.Width, WndHoster.Height);
+
+ //将netterm的父窗口设置为HwndHost
+ SetParent(hwndHost, hwndParent.Handle);
+ return new HandleRef(this, hwndHost);
+ }
+ protected override void DestroyWindowCore(System.Runtime.InteropServices.HandleRef hwnd)
+ {
+ SetWindowLong(hwndHost, GWL_STYLE, oldStyle);
+ SetParent(hwndHost, (IntPtr)0);
+ }
+
+ [StructLayout(LayoutKind.Sequential)]
+ public struct RECT
+ {
+ public int left;
+ public int top;
+ public int right;
+ public int bottom;
+ }
+ [StructLayout(LayoutKind.Sequential)]
+ public struct WindowInfo
+ {
+ public String winTitle;
+ public RECT r;
+ public IntPtr hwnd;
+ }
+ public delegate bool CallBackPtr(IntPtr hwnd, ref WindowInfo WndInfoRef);
+ private static CallBackPtr callBackPtr;
+ private WindowInfo WinInfo;
+ public static bool CallBackProc(IntPtr hwnd, ref WindowInfo WndInfoRef)
+ {
+ StringBuilder str = new StringBuilder(512);
+ GetWindowText(hwnd, str, str.Capacity);
+ Console.WriteLine(str.ToString());
+ if (str.ToString().IndexOf(WndInfoRef.winTitle, 0) >= 0)
+ {
+ WndInfoRef.hwnd = hwnd;
+ GetWindowRect(hwnd, ref (WndInfoRef.r));
+ }
+
+ return true;
+ }
+ public IntPtr FindTheWindow()
+ {
+ callBackPtr = new CallBackPtr(CallBackProc);
+ EnumWindows(callBackPtr, ref WinInfo);
+ return WinInfo.hwnd;
+ }
+ public void RePosWindow(Border b, double screenW, double screenH)
+ {
+ double width = WinInfo.r.right - WinInfo.r.left;
+ double height = WinInfo.r.bottom - WinInfo.r.top;
+
+ double left = (screenW - width) / 2;
+ double right = (screenW - width) / 2;
+ double top = (screenH - height) / 2;
+ double bottom = (screenH - height) / 2;
+
+ //b.Margin = new Thickness(left, top, right, bottom);
+ }
+ }
+}
diff --git a/HaoYue.CQTVShow/HaoYue.CQTVShow.Hub/StaticClass.cs b/HaoYue.CQTVShow/HaoYue.CQTVShow.Hub/StaticClass.cs
index 07bb325..df9f733 100644
--- a/HaoYue.CQTVShow/HaoYue.CQTVShow.Hub/StaticClass.cs
+++ b/HaoYue.CQTVShow/HaoYue.CQTVShow.Hub/StaticClass.cs
@@ -10,6 +10,7 @@ namespace HaoYue.CQTVShow.Hub
public static List StaticShowList = new List();
public static string PlayUrl = "";
public static ShowInfo StaticShowInfo = new ShowInfo();
+ public static int IndexPage = 1;
}