初步完善

This commit is contained in:
皓月 2018-10-06 15:45:19 +08:00
parent 920e63996e
commit 4e627d2801
6 changed files with 268 additions and 31 deletions

View File

@ -64,6 +64,7 @@
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType> <SubType>Designer</SubType>
</ApplicationDefinition> </ApplicationDefinition>
<Compile Include="StartOtherProgarm.cs" />
<Compile Include="StaticClass.cs" /> <Compile Include="StaticClass.cs" />
<Page Include="MainWindow.xaml"> <Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
@ -103,5 +104,8 @@
<LastGenOutput>Settings.Designer.cs</LastGenOutput> <LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None> </None>
</ItemGroup> </ItemGroup>
<ItemGroup>
<Folder Include="PotPlayer\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project> </Project>

View File

@ -11,7 +11,7 @@ namespace HaoYue.CQTVShow.Hub
{ {
public static class HtmlDoIt public static class HtmlDoIt
{ {
public static string GetShowList(int type,int pageindex) public static bool GetShowList(int type,int pageindex)
{ {
string url = ""; string url = "";
if (type == 0) if (type == 0)
@ -36,6 +36,8 @@ namespace HaoYue.CQTVShow.Hub
} }
HtmlWeb htmlweb = new HtmlWeb(); HtmlWeb htmlweb = new HtmlWeb();
try
{
HtmlDocument htmldoc = htmlweb.Load(url); HtmlDocument htmldoc = htmlweb.Load(url);
HtmlNodeCollection hnc = htmldoc.DocumentNode.SelectNodes("//div[@class='main']/ul/li"); HtmlNodeCollection hnc = htmldoc.DocumentNode.SelectNodes("//div[@class='main']/ul/li");
@ -59,8 +61,13 @@ namespace HaoYue.CQTVShow.Hub
} }
} }
return true;
}
catch
{
return false;
}
return "";
} }
public static ShowInfo GetShowInfo(string url) 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(); var hdm3u8 = list.Where(w => w.filetype == 1 && w.Path.Contains("b5000")).FirstOrDefault();
if (hdm3u8 != null) 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; return si;

View File

@ -7,9 +7,15 @@
xmlns:controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro" xmlns:controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
mc:Ignorable="d" 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">
<Grid> <Grid>
<ListBox x:Name="ListBoxShow" HorizontalAlignment="Left" Height="503" VerticalAlignment="Top" Width="409" Margin="6,47,0,0" <ListBox x:Name="ListBoxShow" HorizontalAlignment="Left"
Height="503" Width="409"
VerticalAlignment="Top" Margin="6,47,0,0"
SelectionChanged="ListBoxSelectionChanged" SelectionChanged="ListBoxSelectionChanged"
> >
<ListBox.ItemTemplate> <ListBox.ItemTemplate>
@ -38,7 +44,7 @@
<Grid Background="#FFE5E5E5"/> <Grid Background="#FFE5E5E5"/>
</TabItem> </TabItem>
</TabControl> </TabControl>
<Label x:Name="LabelState" Content="状态" HorizontalAlignment="Left" Margin="7,555,0,0" VerticalAlignment="Top"/> <Label x:Name="LabelState" Content="状态" HorizontalAlignment="Left" Margin="4,586,0,0" VerticalAlignment="Top"/>
<Image x:Name="Image_SelectedShow" HorizontalAlignment="Left" MaxHeight="300" MaxWidth="300" Margin="450,40,0,0" VerticalAlignment="Top" /> <Image x:Name="Image_SelectedShow" HorizontalAlignment="Left" MaxHeight="300" MaxWidth="300" Margin="450,40,0,0" VerticalAlignment="Top" />
<Label x:Name="Label_SelectedName" Content="-" HorizontalAlignment="Left" Margin="450,310,0,0" VerticalAlignment="Top" <Label x:Name="Label_SelectedName" Content="-" HorizontalAlignment="Left" Margin="450,310,0,0" VerticalAlignment="Top"
@ -47,7 +53,15 @@
FontSize="18" FontWeight="Bold"/> FontSize="18" FontWeight="Bold"/>
<Button x:Name="BtnPlay" Content="播 放" HorizontalAlignment="Left" Margin="459,400,0,0" VerticalAlignment="Top" Width="75" <Button x:Name="BtnPlay" Content="播 放" HorizontalAlignment="Left" Margin="459,400,0,0" VerticalAlignment="Top" Width="75"
FontSize="18" FontWeight="Bold" Click="PlayMedia"/> FontSize="18" FontWeight="Bold" Click="PlayMedia"/>
<Button x:Name="BtnPlay_Copy" Content="下 载" HorizontalAlignment="Left" Margin="550,400,0,0" VerticalAlignment="Top" Width="75" <Button x:Name="BtnDown" Content="下 载" HorizontalAlignment="Left" Margin="550,400,0,0" VerticalAlignment="Top" Width="75"
FontSize="18" FontWeight="Bold" Click="PlayMedia"/> FontSize="18" FontWeight="Bold" Click="DownLoadClicked"/>
<TextBox x:Name="TextPageIndex" IsEnabled="False" HorizontalAlignment="Left" Height="27" Margin="77,555,0,0" TextWrapping="Wrap" Text="1" VerticalAlignment="Top" Width="19"/>
<Button x:Name="Btn_UpPage" Content="上一页" IsEnabled="False" HorizontalAlignment="Left" Margin="17,555,0,0" VerticalAlignment="Top" Width="52" Height="26"
Click="UpPage"/>
<Button x:Name="Btn_NextPage" Content="下一页" HorizontalAlignment="Left" Margin="104,555,0,0" VerticalAlignment="Top" Width="52" Height="26"
Click="NextPage"
/>
<Label Content="Powered by axibug.com" HorizontalAlignment="Left" Margin="600,579,0,0" VerticalAlignment="Top" />
</Grid> </Grid>
</controls:MetroWindow> </controls:MetroWindow>

View File

@ -16,6 +16,8 @@ using System.Windows.Shapes;
using MahApps.Metro.Controls; using MahApps.Metro.Controls;
using System.Threading; using System.Threading;
using System.IO; using System.IO;
using System.Diagnostics;
using MahApps.Metro.Controls.Dialogs;
namespace HaoYue.CQTVShow.Hub namespace HaoYue.CQTVShow.Hub
{ {
@ -29,6 +31,7 @@ namespace HaoYue.CQTVShow.Hub
InitializeComponent(); InitializeComponent();
SetShowList(0); SetShowList(0);
this.BtnPlay.IsEnabled = false; this.BtnPlay.IsEnabled = false;
this.ShowMessageAsync("欢迎使用\n皓月云-重庆本土节目播放器\nver 0.1.0 预览版", "本软件目的是给重庆本土电视节目爱好者,\n一个便捷的节目选择器,便捷的观看体验\n节目来源和版权均归 重庆网络广播电视台 所有\n\n请在节目列表选择要观看的栏目", MessageDialogStyle.Affirmative, new MetroDialogSettings() { AffirmativeButtonText = "确定" });
} }
int frist = 1; int frist = 1;
@ -40,6 +43,8 @@ namespace HaoYue.CQTVShow.Hub
frist = 0; frist = 0;
return; return;
} }
StaticClass.IndexPage = 1;
SetShowList(this.TabMeun.SelectedIndex); SetShowList(this.TabMeun.SelectedIndex);
} }
@ -51,13 +56,18 @@ namespace HaoYue.CQTVShow.Hub
this.TabMeun.Dispatcher.BeginInvoke(new myboolsetter(SetTabMeunEnable), false); this.TabMeun.Dispatcher.BeginInvoke(new myboolsetter(SetTabMeunEnable), false);
try try
{ {
HtmlDoIt.GetShowList(type, 1); if (HtmlDoIt.GetShowList(type, StaticClass.IndexPage))
{
this.TabMeun.Dispatcher.BeginInvoke(new myvoidsetter(SetListBoxShow), null); this.TabMeun.Dispatcher.BeginInvoke(new myvoidsetter(SetListBoxShow), null);
this.LabelState.Dispatcher.BeginInvoke(new mystringsetter(SetLabelState), "获取完毕~"); this.LabelState.Dispatcher.BeginInvoke(new mystringsetter(SetLabelState), "获取完毕~");
//切换后自动选择第一个 //切换后自动选择第一个
this.ListBoxShow.Dispatcher.BeginInvoke(new myintsetter(SetListBoxShowSelectIndex), 0); this.ListBoxShow.Dispatcher.BeginInvoke(new myintsetter(SetListBoxShowSelectIndex), 0);
} }
else
{
this.LabelState.Dispatcher.BeginInvoke(new mystringsetter(SetLabelState), "获取失败");
}
}
catch catch
{ {
this.LabelState.Dispatcher.BeginInvoke(new mystringsetter(SetLabelState), "获取失败"); this.LabelState.Dispatcher.BeginInvoke(new mystringsetter(SetLabelState), "获取失败");
@ -77,6 +87,13 @@ namespace HaoYue.CQTVShow.Hub
public void SetListBoxShow() public void SetListBoxShow()
{ {
this.ListBoxShow.ItemsSource = StaticClass.StaticShowList; 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) public void SetTabMeunEnable(bool set)
@ -104,6 +121,7 @@ namespace HaoYue.CQTVShow.Hub
this.Label_SelectedTime.Content = StaticClass.StaticShowList[index].Time; this.Label_SelectedTime.Content = StaticClass.StaticShowList[index].Time;
StaticClass.PlayUrl = StaticClass.StaticShowList[index].ToPath; StaticClass.PlayUrl = StaticClass.StaticShowList[index].ToPath;
this.BtnPlay.IsEnabled = true; this.BtnPlay.IsEnabled = true;
this.BtnDown.IsEnabled = true;
} }
@ -124,7 +142,7 @@ namespace HaoYue.CQTVShow.Hub
ThreadPool.QueueUserWorkItem((obj) => ThreadPool.QueueUserWorkItem((obj) =>
{ {
this.Image_SelectedShow.Dispatcher.BeginInvoke(new myintsetter(SetShowSelected), SelectedIndex); 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); }, null);
} }
@ -189,6 +207,40 @@ namespace HaoYue.CQTVShow.Hub
{ {
//System.Diagnostics.Process.Start(StaticClass.PlayUrl); //System.Diagnostics.Process.Start(StaticClass.PlayUrl);
StaticClass.StaticShowInfo = HtmlDoIt.GetShowInfo(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 = "确定" });
} }
} }
} }

View File

@ -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);
}
}
}

View File

@ -10,6 +10,7 @@ namespace HaoYue.CQTVShow.Hub
public static List<StaticShow> StaticShowList = new List<StaticShow>(); public static List<StaticShow> StaticShowList = new List<StaticShow>();
public static string PlayUrl = ""; public static string PlayUrl = "";
public static ShowInfo StaticShowInfo = new ShowInfo(); public static ShowInfo StaticShowInfo = new ShowInfo();
public static int IndexPage = 1;
} }