完善功能(待续)溜了溜了
This commit is contained in:
parent
4846f02027
commit
8a6ada0966
@ -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">
|
||||
<Grid>
|
||||
<ListBox x:Name="ListBoxShow" HorizontalAlignment="Left" Height="522" VerticalAlignment="Top" Width="346" Margin="10,42,0,0" Background="#EEEEEE">
|
||||
<ListBox x:Name="ListBoxShow" HorizontalAlignment="Left" Height="503" VerticalAlignment="Top" Width="409" Margin="6,47,0,0"
|
||||
SelectionChanged="ListBoxSelectionChanged"
|
||||
>
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
@ -19,9 +21,8 @@
|
||||
</Image>
|
||||
<StackPanel>
|
||||
<Label Content="{Binding Path=Title}" Margin="0,3" FontSize="18" FontWeight="Bold"></Label>
|
||||
<Label Content="{Binding Path=Time}" Margin="0,5,0,3" FontSize="15"></Label>
|
||||
<Label Content="{Binding Path=Time}" Margin="0,5,0,3" FontSize="15"></Label>
|
||||
</StackPanel>
|
||||
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
@ -37,8 +38,14 @@
|
||||
<Grid Background="#FFE5E5E5"/>
|
||||
</TabItem>
|
||||
</TabControl>
|
||||
<Label x:Name="LabelState" Content="状态" HorizontalAlignment="Left" Margin="7,555,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"
|
||||
FontSize="20" FontWeight="Bold"/>
|
||||
<Label x:Name="Label_SelectedTime" Content="-" HorizontalAlignment="Left" Margin="450,350,0,0" VerticalAlignment="Top"
|
||||
FontSize="18" FontWeight="Bold"/>
|
||||
<Button x:Name="BtnPlay" Content="播 放" HorizontalAlignment="Left" Margin="459,400,0,0" VerticalAlignment="Top" Width="75"
|
||||
FontSize="18" FontWeight="Bold" Click="PlayMedia"/>
|
||||
</Grid>
|
||||
</controls:MetroWindow>
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 节目列表选择事件
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
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
|
||||
|
||||
/// <summary>
|
||||
/// 播放媒体时间
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void PlayMedia(object sender, RoutedEventArgs e)
|
||||
{
|
||||
System.Diagnostics.Process.Start(StaticClass.PlayUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ namespace HaoYue.CQTVShow.Hub
|
||||
public class StaticClass
|
||||
{
|
||||
public static List<StaticShow> StaticShowList = new List<StaticShow>();
|
||||
|
||||
public static string PlayUrl = "";
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user