You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1218 lines
53 KiB

using Container.Common;
using Container.Services;
using Newtonsoft.Json;
using QRCoder;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Threading;
using Vlc.DotNet.Wpf;
using Image = System.Windows.Controls.Image;
namespace Container.Win
{
/// <summary>
/// LiveShow.xaml 的交互逻辑
/// </summary>
public partial class LiveShow : Window
{
App app = ((App)System.Windows.Application.Current);
private readonly DirectoryInfo vlcLibDirectory;
DispatcherTimer LiveTimer = new DispatcherTimer();//定时获取是否有直播的线程
Class_Log log = new Class_Log();
//private VlcControl control;
long playTime = 0;
DateTime curDate = DateTime.Now;
DateTime bengindTime = DateTime.Now;
bool isLoad = false;
bool falg = false;
DateTime? dtLiveStop = null;
Dictionary<string, int> livsStopList = new Dictionary<string, int>();
List<DateTime> stopList = new List<DateTime>();
private Socket _socket;
int agreeBeginTop = 730;
int agreeBeginMaxWidth = 700;
int agreeBeginLeft = 625;
/// <summary>
/// 创建双精度动画对象
/// </summary>
DoubleAnimation doubleAnimation = new DoubleAnimation();
/// <summary>
/// 创建双精度动画对象
/// </summary>
DoubleAnimation doubleAnimationEnd = new DoubleAnimation();
/// <summary>
/// 创建双精度动画对象
/// </summary>
DoubleAnimation doubleAnimationImage = new DoubleAnimation();
/// <summary>
/// 创建双精度动画对象
/// </summary>
DoubleAnimation doubleAnimationImageEnd = new DoubleAnimation();
List<string> liveImageList = new List<string>();
//需要移除的图片列表
List<UIElement> ElementList = new List<UIElement>();
int curImageCount = 0;
DispatcherTimer timer = new DispatcherTimer();
public LiveShow()
{
InitializeComponent();
try
{
this.Width = app.ScreenWidth;
this.Height =app.ScreenHeight;
this.gradLive.Width= app.ScreenWidth;
this.gradLive.Height = app.ScreenHeight;
gLoading.SetValue(Canvas.TopProperty, (this.Height - 200) / 2);
gLoading.SetValue(Canvas.LeftProperty, (this.Width - 200) / 2);
//if (this.Width > this.Height)
//{
// control.Width = 608;
// control.Height = 1080;
// control.Margin = new Thickness(640, 0, 0, 0);
// gridMsg.Width = 1920;
// gridMsg.Height = 1080;
// bgGrid.Opacity = 0;
// rightWidth.Width = new GridLength(54);
// leftWidth.Width = new GridLength(48);
// //gLoading.SetValue(Canvas.LeftProperty, 1180);
// cvsAgreeGround.Width = 700;
// cvsAgreeGround.Margin = new Thickness(1050, 0, 0, 250);
// //agreeGrid.SetValue(Canvas.LeftProperty, (object)600);
// Canvas.SetLeft(agreeGrid, 600);
// agreeBeginTop = 710;
// agreeBeginMaxWidth = 700;
// agreeBeginLeft = 600;
//}
//else
//{
// control.Width = 1080;
// control.Height = 1920;
// control.Margin = new Thickness(0, 0, 0, 0);
// gridMsg.Width = 1080;
// gridMsg.Height = 1920;
// bgGrid.Opacity = 0.5;
// rightWidth.Width = new GridLength(30);
// leftWidth.Width = new GridLength(36);
// gLoading.SetValue(Canvas.LeftProperty, (this.Width - 200) / 2);
// cvsAgreeGround.Width = 280;
// cvsAgreeGround.Margin = new Thickness(800, 0, 0, 550);
// //agreeGrid.SetValue(Canvas.LeftProperty, (object)120);
// Canvas.SetLeft(agreeGrid, 120);
// agreeBeginTop = 1250;
// agreeBeginMaxWidth = 280;
// agreeBeginLeft = 120;
//}
var currentAssembly = Assembly.GetEntryAssembly();
var currentDirectory = new FileInfo(currentAssembly.Location).DirectoryName;
// Default installation path of VideoLAN.LibVLC.Windows
vlcLibDirectory = new DirectoryInfo(currentDirectory);
}
catch (Exception e)
{
log.WriteLogFile(e.ToString(), "liveshowerror");
}
}
const int WM_CLOSE = 0x0010;//关闭窗体
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr FindWindow(string IpClassName, string IpWindowName);
[DllImport("User32.dll", EntryPoint = "SendMessage")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
private void Window_Loaded(object sender, RoutedEventArgs e)
{
try
{
//HttpMessage httpmessage = new HttpMessage();
LiveTimer.Tick += new EventHandler(LiveTimer_Tick);
LiveTimer.Interval = TimeSpan.FromSeconds(1);
timer.Interval = TimeSpan.FromMilliseconds(2000);
timer.Tick += new EventHandler(timer_Tick);
AniamtionLoad();
LoadScoket();
//httpmessage.LoadCurrentLive();
Action ac = new Action(()=> {
ConvertLive();
LoadData();
//app.curLive.hFilePath = app.live.HFilePath;
StartVideo(app.curLive.liveurl);
LiveTimer.Start();
});
ac.BeginInvoke(null,null);
}
catch (Exception ex)
{
log.WriteLogFile(ex.ToString(), "liveshowerror");
}
}
private void ConvertLive() {
var live = app.live;
app.curLive.CouponInfo = live.CouponInfo;
app.curLive.floorName = live.FloorName;
app.curLive.hFilePath = live.HFilePath;
app.curLive.houseNum = live.HouseNum;
app.curLive.likes = live.Likes;
app.curLive.liveurl = live.LiveUrl;
app.curLive.logoPath = live.LogoPath;
app.curLive.mallName = live.MallName;
app.curLive.qrCode = live.QRCode;
app.curLive.shopName = live.ShopName;
app.curLive.vFilePath = live.VFilePath;
app.curLive.watchNum = live.WatchNum;
}
private void LoadScoket()
{
//1、创建Socket对象
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
_socket = socket;
//2、连接服务器,绑定IP 与 端口
IPEndPoint iPEndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 8000);
try
{
socket.Connect(iPEndPoint);
}
catch (Exception)
{
//MessageBox.Show("连接失败,请重新连接!", "提示");
//return;
}
//3、接收消息
ThreadPool.QueueUserWorkItem(new WaitCallback(ReceiveServerMsg), socket);
}
/// <summary>
/// 不断接收客户端信息子线程方法
/// </summary>
/// <param name="obj">参数Socke对象</param>
private void ReceiveServerMsg(object obj)
{
var proxSocket = obj as Socket;
//创建缓存内存,存储接收的信息 ,不能放到while中,这块内存可以循环利用
byte[] data = new byte[1020 * 1024];
while (true)
{
int len;
try
{
//接收消息,返回字节长度
len = proxSocket.Receive(data, 0, data.Length, SocketFlags.None);
}
catch (Exception ex)
{
return;//让方法结束,终结当前客户端数据的异步线程,方法退出,即线程结束
}
if (len > 0)//判断接收的字节数
{
////将消息显示到TxtLog
string msgStr = Encoding.Default.GetString(data, 0, len);
Dictionary<string, Object> Commands = JsonConvert.DeserializeObject<Dictionary<string, Object>>(msgStr);
var type = Commands["Type"].ToString();
if (type == "like")
{
Dictionary<string, Object> Parameter = JsonConvert.DeserializeObject<Dictionary<string, Object>>(Commands["Parameter"].ToString());
Random rd = new Random();
ControlsLoadAgree(rd.Next(2, 6));
}
else if (type == "watchnum")
{
Dictionary<string, Object> Parameter = JsonConvert.DeserializeObject<Dictionary<string, Object>>(Commands["Parameter"].ToString());
this.TxtDistance.Dispatcher.Invoke(new Action(delegate
{
if (string.IsNullOrEmpty(app.curLive.floorName))
{
this.TxtDistance.Text = "扫码人数 " + Parameter["watchNum"].ToString();
}
else
{
this.TxtDistance.Text = "扫码人数 " + Parameter["watchNum"].ToString() + " | " + app.curLive.floorName;
}
}));
}
else if (type == "livecoupon")
{
this.gridCoupon.Dispatcher.Invoke(new Action(delegate
{
this.gridCoupon.Visibility = Visibility.Visible;
if (!string.IsNullOrEmpty(app.curLive.CouponInfo.Title))
{
this.couponName.Text = app.curLive.CouponInfo.Title;
}
else
{
//this.TxtDistance.Text = "扫码人数 " + app.curLive.watchNum + " | " + app.curLive.floorName;
this.couponName.Text = "";
}
if (!string.IsNullOrEmpty(app.curLive.CouponInfo.Intro))
{
this.couponIntro.Text = app.curLive.CouponInfo.Intro;
}
else
{
//this.TxtDistance.Text = "扫码人数 " + app.curLive.watchNum + " | " + app.curLive.floorName;
this.couponIntro.Text = "";
}
this.couponNum.Text = app.curLive.CouponInfo.Received + "/" + app.curLive.CouponInfo.TotalNum;
}));
CreateQR(app.curLive.CouponInfo.QrCode);
}
else if (type == "getcoupon") {
this.gridCoupon.Dispatcher.Invoke(new Action(delegate
{
this.couponNum.Text = app.curLive.CouponInfo.Received + "/" + app.curLive.CouponInfo.TotalNum;
}));
}
else if (type == "shutdowncoupon")
{
this.gridCoupon.Dispatcher.Invoke(new Action(delegate
{
this.gridCoupon.Visibility = Visibility.Hidden;
}));
}
else if (type == "ADImage")
{
//this.cvsAD.Dispatcher.Invoke(new Action(delegate
//{
// try
// {
// string filefolder = AppDomain.CurrentDomain.BaseDirectory + "/liveadfile";
// try
// {
// if (!Directory.Exists(filefolder))
// {
// DirectoryInfo directoryInfo = new DirectoryInfo(filefolder);
// directoryInfo.Create();
// }
// }
// catch (Exception ex)
// {
// log.WriteLogFile(ex.ToString());
// }
// HttpClient httpClient = new HttpClient();
// string fileName = "";
// if (httpClient.DownLoadImage(app.curLive.hFilePath, "liveadfile", ref fileName))
// {
// Image simpleImage = new Image();
// simpleImage.Width = 800;
// simpleImage.Height = 250;
// simpleImage.Stretch = Stretch.Fill;
// //simpleImage.Margin = new Thickness(0, 0, 20, 0);
// Canvas.SetLeft(simpleImage, 0);
// BitmapImage bi = new BitmapImage();
// // BitmapImage.UriSource must be in a BeginInit/EndInit block.
// bi.BeginInit();
// bi.UriSource = new Uri(fileName, UriKind.RelativeOrAbsolute);
// bi.EndInit();
// simpleImage.Stretch = Stretch.Fill;
// simpleImage.Source = bi;
// //cvsAD.Children.Clear();
// //cvsAD.Children.Add(simpleImage);
// }
// else
// {
// log.WriteLogFile("直播广告图下载失败");
// }
// }
// catch (Exception ex)
// {
// log.WriteLogFile(ex.ToString());
// }
//}));
}
else if (type == "Image")
{
this.cvsGround.Dispatcher.Invoke(new Action(delegate
{
try
{
List<string> imageList = new List<string>();
bool isLoad = false;
foreach (var item in app.curLive.vFilePath)
{
string filefolder = AppDomain.CurrentDomain.BaseDirectory + "/liveImageFile";
try
{
if (!Directory.Exists(filefolder))
{
DirectoryInfo directoryInfo = new DirectoryInfo(filefolder);
directoryInfo.Create();
}
}
catch (Exception ex)
{
log.WriteLogFile(ex.ToString());
}
HttpClient httpClient = new HttpClient();
string fileName = "";
if (!httpClient.CheckImageIsExists(item, "liveImageFile", ref fileName))
{
if (httpClient.DownLoadImage(item, "liveImageFile", ref fileName))
imageList.Add(fileName);
else
{
log.WriteLogFile("直播广告图下载失败");
}
isLoad = true;
}
else
{
imageList.Add(fileName);
if (JsonConvert.SerializeObject(liveImageList).Contains(fileName.Substring(fileName.LastIndexOf('/')+1)))
{
isLoad = true;
}
}
}
if (isLoad)
{
liveImageList = imageList;
cvsGround.Children.Clear();
ControlsLoad(imageList);
if (imageList.Count > 4)
{
timer.Start();
}
else
{
timer.Stop();
}
curImageCount = 0;
}
}
catch (Exception ex)
{
log.WriteLogFile(ex.ToString());
}
}));
}
}
}
}
private void timer_Tick(object sender, EventArgs e)
{
//Random rd = new Random();
//ControlsLoadAgree(rd.Next(2, 6));
DoMove(-206);
}
/// <summary>
/// 图片的运动方法
/// </summary>
private void AniamtionLoad()
{
doubleAnimation.Duration = TimeSpan.FromSeconds(0.5);//设置动画时间线长度
doubleAnimation.AccelerationRatio = 0.1;//动画加速
doubleAnimation.DecelerationRatio = 0.5;//动画减速
doubleAnimation.FillBehavior = FillBehavior.HoldEnd;//设置动画完成后执行的操作
doubleAnimationEnd.Duration = TimeSpan.FromSeconds(0.5);//设置动画时间线长度
doubleAnimationEnd.AccelerationRatio = 0.1;//动画加速
doubleAnimationEnd.DecelerationRatio = 0.5;//动画减速
doubleAnimationEnd.To = -800;
doubleAnimationImage.Duration = TimeSpan.FromSeconds(0.5);//设置动画时间线长度
doubleAnimationImage.AccelerationRatio = 0.1;//动画加速
doubleAnimationImage.DecelerationRatio = 0.5;//动画减速
doubleAnimationImage.FillBehavior = FillBehavior.HoldEnd;//设置动画完成后执行的操作
doubleAnimationImageEnd.Duration = TimeSpan.FromSeconds(0.5);//设置动画时间线长度
doubleAnimationImageEnd.AccelerationRatio = 0.1;//动画加速
doubleAnimationImageEnd.DecelerationRatio = 0.5;//动画减速
doubleAnimationImageEnd.To = -206;
}
private async void LoadData()
{
Class_Log log = new Class_Log();
try
{
if (app.curLive != null)
{
if (!string.IsNullOrEmpty(app.curLive.logoPath))
{
this.ImgLogo.Dispatcher.Invoke(new Action(delegate
{
log.WriteLogFile(app.curLive.logoPath.Replace("\\", @"/"), "22222");
Uri uriLogo = new Uri(app.curLive.logoPath.Replace("\\",@"/"), UriKind.Absolute);
this.ImgLogo.Source = BitmapFrame.Create(uriLogo);
}));
}
else
{
this.ImgLogo.Dispatcher.Invoke(new Action(delegate
{
Uri uriLogo = new Uri(@"/image/liveicon/admin.png", UriKind.RelativeOrAbsolute);
this.ImgLogo.Source = BitmapFrame.Create(uriLogo);
}));
}
this.TxtName.Dispatcher.Invoke(new Action(delegate
{
this.TxtName.Content = string.IsNullOrEmpty(app.curLive.shopName) ? app.curLive.mallName : app.curLive.shopName;
this.TxtName.TextSource = string.IsNullOrEmpty(app.curLive.shopName) ? app.curLive.mallName : app.curLive.shopName;
}));
this.TxtDistance.Dispatcher.Invoke(new Action(delegate
{
if (string.IsNullOrEmpty(app.curLive.floorName))
{
this.TxtDistance.Text = "";
}
else
{
//this.TxtDistance.Text = "扫码人数 " + app.curLive.watchNum + " | " + app.curLive.floorName;
this.TxtDistance.Text = app.curLive.floorName+" | "+app.curLive.houseNum;
}
}));
if (app.curLive.CouponInfo != null)
{
this.gridCoupon.Dispatcher.Invoke(new Action(delegate
{
this.gridCoupon.Visibility = Visibility.Visible;
if (!string.IsNullOrEmpty(app.curLive.CouponInfo.Title))
{
this.couponName.Text = app.curLive.CouponInfo.Title;
}
else
{
//this.TxtDistance.Text = "扫码人数 " + app.curLive.watchNum + " | " + app.curLive.floorName;
this.couponName.Text = "";
}
if (!string.IsNullOrEmpty(app.curLive.CouponInfo.Intro))
{
this.couponIntro.Text = app.curLive.CouponInfo.Intro;
}
else
{
//this.TxtDistance.Text = "扫码人数 " + app.curLive.watchNum + " | " + app.curLive.floorName;
this.couponIntro.Text = "";
}
this.couponNum.Text = app.curLive.CouponInfo.Received+ "/"+app.curLive.CouponInfo.TotalNum;
}));
CreateQR(app.curLive.CouponInfo.QrCode);
}
else {
this.gridCoupon.Dispatcher.Invoke(new Action(delegate
{
this.gridCoupon.Visibility = Visibility.Hidden;
}));
}
//this.TxtName.Text = app.curLive.shopName;
//this.TxtDistance.Text = "扫码人数 " + app.curLive.likes + " | " + app.curLive.floorName;
//this.Dispatcher.Invoke(new Action(() =>
//{
//if (this.Width > this.Height)
//{
// //SFile.Visibility = Visibility.Hidden;
// LogoBG.Color = (System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("White");
// LogoQR.Color = (System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("White");
//}
//else
//{
// LogoBG.Color = (System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("Black");
// LogoQR.Color = (System.Windows.Media.Color)System.Windows.Media.ColorConverter.ConvertFromString("Black");
//}
//this.cvsAD.Dispatcher.Invoke(new Action(delegate
//{
// try
// {
// string filefolder = AppDomain.CurrentDomain.BaseDirectory + "/liveadfile";
// //IntPtr Win = FindWindow(null, "ADInsert");
// //if (Win != null)
// //{
// // //SetWindowPos(Win, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
// // SendMessage(Win, WM_CLOSE, 0, 0); // 调用了 发送消息 发送关闭窗口的消息
// //}
// try
// {
// if (!Directory.Exists(filefolder))
// {
// DirectoryInfo directoryInfo = new DirectoryInfo(filefolder);
// directoryInfo.Create();
// }
// }
// catch (Exception ex)
// {
// log.WriteLogFile(ex.ToString());
// }
// HttpClient httpClient = new HttpClient();
// string fileName = "";
// if (httpClient.DownLoadImage(app.curLive.hFilePath, "liveadfile", ref fileName))
// {
// Image simpleImage = new Image();
// simpleImage.Width = 800;
// simpleImage.Height = 250;
// simpleImage.Stretch = Stretch.Fill;
// //simpleImage.Margin = new Thickness(0, 0, 20, 0);
// Canvas.SetLeft(simpleImage, 0);
// BitmapImage bi = new BitmapImage();
// // BitmapImage.UriSource must be in a BeginInit/EndInit block.
// bi.BeginInit();
// bi.UriSource = new Uri(fileName, UriKind.RelativeOrAbsolute);
// bi.EndInit();
// simpleImage.Stretch = Stretch.Fill;
// simpleImage.Source = bi;
// cvsAD.Children.Add(simpleImage);
// //double transferLeft = Convert.ToDouble(simpleImage.GetValue(Canvas.LeftProperty));
// //doubleAnimation.To = 0;
// //simpleImage.BeginAnimation(Canvas.LeftProperty, doubleAnimation);//设置动画应用的属性并启动动画
// //cvsAD.Children[0].BeginAnimation(Canvas.LeftProperty, doubleAnimationEnd);//设置动画应用的属性并启动动画
// //doubleAnimationEnd.Completed += SbQueOnCompleted; //设置动画结束后的事件
// }
// else
// {
// log.WriteLogFile("直播广告图下载失败");
// }
// }
// catch (Exception ex)
// {
// log.WriteLogFile(ex.ToString());
// }
//}));
this.cvsGround.Dispatcher.Invoke(new Action(delegate
{
try
{
List<string> imageList = new List<string>();
foreach (var item in app.curLive.vFilePath)
{
string filefolder = AppDomain.CurrentDomain.BaseDirectory + "/liveImageFile";
try
{
if (!Directory.Exists(filefolder))
{
DirectoryInfo directoryInfo = new DirectoryInfo(filefolder);
directoryInfo.Create();
}
}
catch (Exception ex)
{
log.WriteLogFile(ex.ToString());
}
HttpClient httpClient = new HttpClient();
string fileName = "";
if (httpClient.DownLoadImage(item, "liveImageFile", ref fileName))
{
imageList.Add(fileName);
}
else
{
log.WriteLogFile("直播广告图下载失败");
}
}
liveImageList = imageList;
ControlsLoad(imageList);
if (imageList.Count > 4)
{
timer.Start();
}
else {
timer.Stop();
}
curImageCount = 0;
}
catch (Exception ex)
{
log.WriteLogFile(ex.ToString());
}
}));
// }));
}
}
catch (Exception ex)
{
log.WriteLogFile(ex.ToString(), "LivePage");
}
}
/// <summary>
/// 循环产生图片
/// </summary>
/// <param name="num">产生图片的个数</param>
/// <param name="Direction">产生图片的方向</param>
/// <param name="Location">产生图片的位置</param>
/// <returns></returns>
private void ControlsLoadAgree(int num)
{
List<TextBlock> tbList = new List<TextBlock>();
Random rd = new Random();
for (int i = 0; i < num; i++)
{
double timeSpan = rd.Next(1, 7);
int liveImagePath = rd.Next(1, 6);
Image simpleImage = new Image();
simpleImage.Width = 75;
simpleImage.Height = 75;
Canvas.SetRight(simpleImage, 75);
Canvas.SetBottom(simpleImage, 35);
BitmapImage bi = new BitmapImage();
// BitmapImage.UriSource must be in a BeginInit/EndInit block.
bi.BeginInit();
bi.UriSource = new Uri(@"/image/liveicon/" + liveImagePath + ".png", UriKind.RelativeOrAbsolute);
bi.EndInit();
simpleImage.Stretch = Stretch.Fill;
simpleImage.Source = bi;
//cvsAgreeGround.Children.Add(simpleImage);
DoubleAnimation doubleAnimation1 = new DoubleAnimation();
doubleAnimation1.From = agreeBeginLeft;
doubleAnimation1.To = rd.Next(0, agreeBeginMaxWidth);
DoubleAnimation doubleAnimation2 = new DoubleAnimation();
doubleAnimation1.Duration = TimeSpan.FromSeconds(timeSpan);//设置动画时间线长度
//doubleAnimation1.AccelerationRatio = 0;//动画加速
//doubleAnimation1.DecelerationRatio = 0.5;//动画减速
doubleAnimation2.Duration = TimeSpan.FromSeconds(timeSpan);//设置动画时间线长度
//doubleAnimation2.AccelerationRatio = 0;//动画加速
//doubleAnimation2.DecelerationRatio = 0.5;//动画减速
simpleImage.BeginAnimation(Canvas.LeftProperty, doubleAnimation1);//设置动画应用的属性并启动动
doubleAnimation2.From = agreeBeginTop;
doubleAnimation2.To = 0;
simpleImage.BeginAnimation(Canvas.TopProperty, doubleAnimation2);//设置动画应用的属性并启动动
DoubleAnimation da = new DoubleAnimation();
da.From = 1;
da.To = 0.3;
da.Duration = TimeSpan.FromSeconds(timeSpan);
//da.Completed += (s, e) =>
//{
// cvsAgreeGround.Children.Remove(simpleImage);
//};
simpleImage.BeginAnimation(OpacityProperty, da);
//TextBlock textBlock = new TextBlock();
//textBlock.Width = 75;
//textBlock.Height = 75;
//Canvas.SetRight(textBlock, 75);
//Canvas.SetBottom(textBlock, 35);
//textBlock.Text = "♥";
//textBlock.FontSize = 60;
//textBlock.Foreground = PickRandomBrush(rd);
//cvsAgreeGround.Children.Add(textBlock);
//tbList.Add(textBlock);
//DoubleAnimation doubleAnimation1 = new DoubleAnimation();
//doubleAnimation1.From = agreeBeginLeft;
//doubleAnimation1.To = rd.Next(0, agreeBeginMaxWidth);
//DoubleAnimation doubleAnimation2 = new DoubleAnimation();
//doubleAnimation1.Duration = TimeSpan.FromSeconds(timeSpan);//设置动画时间线长度
////doubleAnimation1.AccelerationRatio = 0;//动画加速
////doubleAnimation1.DecelerationRatio = 0.5;//动画减速
//doubleAnimation2.Duration = TimeSpan.FromSeconds(timeSpan);//设置动画时间线长度
////doubleAnimation2.AccelerationRatio = 0;//动画加速
////doubleAnimation2.DecelerationRatio = 0.5;//动画减速
//textBlock.BeginAnimation(Canvas.LeftProperty, doubleAnimation1);//设置动画应用的属性并启动动
//doubleAnimation2.From = agreeBeginTop;
//doubleAnimation2.To = 0;
//textBlock.BeginAnimation(Canvas.TopProperty, doubleAnimation2);//设置动画应用的属性并启动动
//DoubleAnimation da = new DoubleAnimation();
//da.From = 1;
//da.To = 0.3;
//da.Duration = TimeSpan.FromSeconds(timeSpan);
//da.Completed += (s, e) =>
//{
// cvsAgreeGround.Children.Remove(textBlock);
//};
//textBlock.BeginAnimation(OpacityProperty, da);
}
}
private System.Windows.Media.Brush PickRandomBrush(Random rnd)
{
System.Windows.Media.Brush result = System.Windows.Media.Brushes.Transparent;
Type brushesType = typeof(System.Windows.Media.Brushes);
PropertyInfo[] properties = brushesType.GetProperties();
int random = rnd.Next(properties.Length);
result = (System.Windows.Media.Brush)properties[random].GetValue(null, null);
return result;
}
private void SbQueOnCompleted(object sender, EventArgs eventArgs)
{
//循环删除图片
//cvsAD.Children.RemoveAt(0);
}
private void SbImageQueOnCompleted(object sender, EventArgs eventArgs)
{
//循环删除图片
foreach (UIElement element in ElementList)
{
cvsGround.Children.Remove(element);
}
}
private void ControlsLoad(List<string> imageList)
{
for (int i = 0; i < imageList.Count; i++)
{
// Create the image element.
Image simpleImage = new Image();
simpleImage.Width = 180;
simpleImage.Height = 180;
simpleImage.Stretch = Stretch.Fill;
Canvas.SetTop(simpleImage, i * 206);
simpleImage.Stretch = Stretch.Fill;
BitmapImage bi = new BitmapImage();
// BitmapImage.UriSource must be in a BeginInit/EndInit block.
bi.BeginInit();
bi.UriSource = new Uri(imageList[i], UriKind.RelativeOrAbsolute);
bi.EndInit();
simpleImage.Source = bi;
cvsGround.Children.Add(simpleImage);
}
}
private void DoMove(double to)
{
int Direction = 0;
ElementList.Clear();
//添加图片的位置
double endDouble = 0;
//循环移动图片的位置 并且判断需要删除的图片
foreach (UIElement element in cvsGround.Children)
{
double transferLeft = Convert.ToDouble(element.GetValue(Canvas.TopProperty));
doubleAnimationImage.To = to + transferLeft;
element.BeginAnimation(Canvas.TopProperty, doubleAnimationImage);//设置动画应用的属性并启动动画
transferLeft = Convert.ToDouble(element.GetValue(Canvas.TopProperty));
if (to < 0)
{
if (transferLeft <= 0)
{
ElementList.Add(element);
}
if (transferLeft > endDouble)
{
endDouble = transferLeft;
}
Direction = 1;
}
else
{
if (transferLeft > cvsGround.Width)
{
ElementList.Add(element);
}
if (transferLeft < endDouble)
{
endDouble = transferLeft;
}
Direction = 0;
}
}
List<Image> imgList = new List<Image>();
//考虑每次移动的误差 endDouble 都要 加上图片的 宽度
if (to <= 0)
{
imgList = ControlsLoad(ElementList.Count, Direction, endDouble + 206);
}
else
{
imgList = ControlsLoad(ElementList.Count, Direction, endDouble - 206);
}
curImageCount = (curImageCount + ElementList.Count >= liveImageList.Count) ? (curImageCount + ElementList.Count - liveImageList.Count) : (curImageCount + ElementList.Count);
//循环移动 添加的图片
foreach (UIElement element in imgList)
{
double transferLeft = Convert.ToDouble(element.GetValue(Canvas.TopProperty));
doubleAnimationImage.To = to + transferLeft;
element.BeginAnimation(Canvas.TopProperty, doubleAnimationImage);//设置动画应用的属性并启动动画
}
//循环删除图片
foreach (UIElement element in ElementList)
{
element.BeginAnimation(Canvas.TopProperty, doubleAnimationImageEnd);//设置动画应用的属性并启动动画
doubleAnimationImageEnd.Completed += SbImageQueOnCompleted; //设置动画结束后的事件
}
//System.Windows.Forms.MessageBox.Show(cvsGround.Children.Count + "");
}
/// <summary>
/// 循环产生图片
/// </summary>
/// <param name="num">产生图片的个数</param>
/// <param name="Direction">产生图片的方向</param>
/// <param name="Location">产生图片的位置</param>
/// <returns></returns>
private List<Image> ControlsLoad(int num, int Direction, double Location)
{
List<Image> imgList = new List<Image>();
for (int i = 0; i < num; i++)
{
Image simpleImage = new Image();
simpleImage.Width = 180;
simpleImage.Height = 180;
simpleImage.Stretch = Stretch.Fill;
//simpleImage.Margin = new Thickness(0, 0, 20, 0);
Canvas.SetTop(simpleImage, i * 206 + Location);
BitmapImage bi = new BitmapImage();
// BitmapImage.UriSource must be in a BeginInit/EndInit block.
bi.BeginInit();
string fileName = string.Empty;
if (curImageCount + i >= liveImageList.Count)
{
fileName = liveImageList[curImageCount + i - liveImageList.Count];
}
else
{
fileName = liveImageList[curImageCount + i];
}
bi.UriSource = new Uri(fileName, UriKind.RelativeOrAbsolute);
bi.EndInit();
simpleImage.Source = bi;
cvsGround.Children.Add(simpleImage);
imgList.Add(simpleImage);
}
return imgList;
}
private void CreateQR(string plainText)
{
this.couponQR.Dispatcher.Invoke(new Action(delegate
{
Class_Log log = new Class_Log();
try
{
QRCodeGenerator qrGenerator = new QRCoder.QRCodeGenerator();
//QRCodeGenerator.ECCLevel:纠错能力,Q级:约可纠错25%的数据码字
QRCodeData qrCodeData = qrGenerator.CreateQrCode(plainText, QRCodeGenerator.ECCLevel.Q);
QRCode qrcode = new QRCode(qrCodeData);
Bitmap qrCodeImage = qrcode.GetGraphic(15);
MemoryStream ms = new MemoryStream();
qrCodeImage.Save(ms, ImageFormat.Png);
ImageSourceConverter imageSourceConverter = new ImageSourceConverter();
couponQR.Source = (ImageSource)imageSourceConverter.ConvertFrom(ms);
}
catch (Exception ex)
{
log.WriteLogFile(ex.ToString(), "qr");
}
}));
}
private void StartVideo(string videoPath)
{
try
{
//this.control?.Dispose();
//this.control = new VlcControl();
//this.mainp.Content = this.control;
this.control.SourceProvider.CreatePlayer(this.vlcLibDirectory);
this.control.SourceProvider.MediaPlayer.PositionChanged += (_, args) =>
{
curDate = DateTime.Now;
//log.WriteLogFile(args.NewPosition.ToString(), "PositionChanged");
//this.control.SourceProvider.MediaPlayer.Position=
//string message = $"libVlc : {args.Level} {args.Message} @ {args.Module}";
//System.Diagnostics.Debug.WriteLine(message);
};
this.control.SourceProvider.MediaPlayer.Buffering += (_, args) =>
{
bengindTime = DateTime.Now;
//string message = $"libVlc : {args.Level} {args.Message} @ {args.Module}";
//System.Diagnostics.Debug.WriteLine(message);
};
var options = new string[]
{
"-I",
"dummy",
"--ignore-config",
"--extraintf=logger",
"--verbose=2",
"--fullscreen",
"--network-caching=300",
"--live-caching=300",
"--sout-mux-caching=300",
"--file-caching=300",
"--codec=mediacodec,iomx,all",
"--quiet-synchro",
" --clock-synchro=300",
"--network-synchronisation"
// "--plugin-path=" + this.vlcLibDirectory+ "\\plugins\\",
// "-I",
// "--no-sout-bridge-in-placeholder-switch-on-iframe",
// "--mosaic-delay=0",
// "--sout-display-delay=0",
//"dummy",
//"--ignore-config",
//"--extraintf=logger",
//"--verbose=2",
//"--fullscreen",
//"--network-caching=100",
//"--live-caching=100",
//"--sout-mux-caching=100",
//"--file-caching=100",
//"--codec=mediacodec,iomx,all",
//"--quiet-synchro",
//" --clock-synchro=100",
//"--network-synchronisation",
//"--screen-caching=100",
//"--rtsp-caching=100",
//"--fake-caching=100",
//"--http-caching=100",
//"--mms-caching=100",
//"--realrtsp-caching=100",
//"--skip-frames",
//"--drop-late-frames"
//, "--sout=#transcode{vcodec=h264,acodec=mpga,ab=128,channels=2,samplerate=44100}"
};
//control.SourceProvider.MediaPlayer.Rate = 2.5f;
control.SourceProvider.MediaPlayer.Play(new Uri(videoPath));
dtLiveStop = DateTime.Now;
//timer.Start();
//control.SourceProvider.MediaPlayer.Time = 8000;
}
catch (Exception ex)
{
log.WriteLogFile(ex.ToString(), "liveshowerror");
}
}
private void LiveTimer_Tick(object sender, EventArgs e)
{
Class_Log log = new Class_Log();
if (!this.control.SourceProvider.MediaPlayer.IsPlaying())
{
loading.Dispatcher.Invoke((Action)(() =>
{
loading.Visibility = Visibility.Visible;
}));
if ((dtLiveStop.HasValue && dtLiveStop.Value.AddMinutes(1) <= DateTime.Now))
{
IntPtr WinLivePage = FindWindow(null, "LivePage"); //置顶窗体
if (WinLivePage != null && WinLivePage != IntPtr.Zero)
{
SendMessage(WinLivePage, WM_CLOSE, 0, 0);
}
app.isLoadLive = false;
IntPtr windowWin = FindWindow(null, "WindowViewNew"); //置顶窗体
if ((windowWin == null || windowWin == IntPtr.Zero))
{
Action UploadApp = new Action(() =>
{
App.Current.Dispatcher.Invoke((Action)(() =>
{
try
{
WindowViewNew windowView = new WindowViewNew(0);
windowView.Show();
}
catch (Exception ex)
{
log.WriteLogFile(ex.ToString(), "errorrrr");
}
}));
});
UploadApp.BeginInvoke(null, null);
}
this.Dispatcher.Invoke((Action)(() =>
{
LiveTimer.Stop();
this.control?.Dispose();
this.Close();
}));
}
return;
}
Action ac = new Action(() =>
{
var curLiveDate = DateTime.Now;
try
{
//if ((dtLiveStop.HasValue && dtLiveStop.Value.AddMinutes(1) <= DateTime.Now) )
var removeList = stopList.Where(i => i < curLiveDate.AddMinutes(-1)).ToList();
stopList.RemoveRange(0, removeList.Count);
if ((dtLiveStop.HasValue && dtLiveStop.Value.AddMinutes(1) <= DateTime.Now) || stopList.Count >= 5)
//if ((dtLiveStop.HasValue && dtLiveStop.Value.AddMinutes(1) <= DateTime.Now)|| (livsStopList.Keys.Contains(curLiveDate.ToShortTimeString())&&livsStopList[curLiveDate.ToShortTimeString()]>=6))
{
IntPtr WinLivePage = FindWindow(null, "LivePage"); //置顶窗体
if (WinLivePage != null && WinLivePage != IntPtr.Zero)
{
SendMessage(WinLivePage, WM_CLOSE, 0, 0);
}
app.isLoadLive = false;
IntPtr windowWin = FindWindow(null, "WindowViewNew"); //置顶窗体
if ((windowWin == null || windowWin == IntPtr.Zero))
{
Action UploadApp = new Action(() =>
{
App.Current.Dispatcher.Invoke((Action)(() =>
{
try
{
WindowViewNew windowView = new WindowViewNew(0);
windowView.Show();
}
catch (Exception ex)
{
log.WriteLogFile(ex.ToString(), "errorrrr");
}
}));
});
UploadApp.BeginInvoke(null, null);
}
this.Dispatcher.Invoke((Action)(() =>
{
LiveTimer.Stop();
this.control?.Dispose();
this.Close();
}));
}
else
{
isLoad = true;
if (curDate <= DateTime.Now)
{
if (playTime < this.control.SourceProvider.MediaPlayer.Time)
{
playTime = this.control.SourceProvider.MediaPlayer.Time;
loading.Dispatcher.Invoke((Action)(() =>
{
loading.Visibility = Visibility.Hidden;
}));
dtLiveStop = null;
}
else
{
if (!dtLiveStop.HasValue)
{
dtLiveStop = DateTime.Now;
stopList.Add(curLiveDate);
}
loading.Dispatcher.Invoke((Action)(() =>
{
loading.Visibility = Visibility.Visible;
}));
}
}
else
{
loading.Dispatcher.Invoke((Action)(() =>
{
loading.Visibility = Visibility.Hidden;
}));
dtLiveStop = null;
}
}
}
catch (Exception ex)
{
log.WriteLogFile(ex.ToString(), "errorrrrrrr");
}
});
ac.BeginInvoke(null, null);
}
private void WindowView_Closing(object sender, EventArgs e)
{
try
{
app.isLoadLive = false;
this.control?.Dispose();
LiveTimer.Stop();
}
catch (Exception ex)
{
log.WriteLogFile(ex.ToString(), "WindowViewErrorlog");
}
}
}
}