using Container.Business; using Container.Common; using Container.Model; using Container.Services; using Newtonsoft.Json; using System; using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Diagnostics; using System.Globalization; using System.IO; using System.Linq; 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.Interop; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Media.Imaging; using System.Windows.Shapes; using System.Windows.Threading; using Transitionals; namespace Container.Win { /// /// WindowViewNew.xaml 的交互逻辑 /// public partial class WindowViewNew : Window { double beginX = 0; double endX = 0; double beginY = 0; double endY = 0; //bool isSysProg = true; //DispatcherTimer VCDTimer = new DispatcherTimer();//停止播放视频的定时器 //DispatcherTimer GCTimer = new DispatcherTimer(); //DispatcherTimer ProgramSyncTimer = new DispatcherTimer();//停止播放视频的定时器 //private List> ucListSys = new List>();//记录最新的屏保列表 //private List> ucNewsList = new List>(); //记录插播列表 //private List> ucList = new List>(); //记录插播列表 private DateTime? curLoadDate; DispatcherTimer LoadScreenTimer = new DispatcherTimer();//隔天加载节目 DispatcherTimer LoadProgIsSync = new DispatcherTimer();//隔天加载节目 PlayBackManage pbm; //private int duration = 0;//视频总时长; //int currentTime = 0; //int ImageShowTime = 0; App app = ((App)Application.Current); Class_Log log = new Class_Log(); //UserControl MyUc = new UserControl(); //bool isplay = false; //public bool isclose = false; //public bool Mainclose = false; MouseHook mh = new MouseHook(); // WebSocketManage web = new WebSocketManage(); //private List navDateList = new List(); //WebSocketForFaceManage webForFace = new WebSocketForFaceManage(); //WebSocketForProgram webForProgram = new WebSocketForProgram(); JService jService = new JService(); private double percentHeight = 1; int isShowCountDown = 0; List videoList = new List(); /// /// 鼠标位置数组 /// ArrayList Points = new ArrayList();// IntPtr hWaitTimer = IntPtr.Zero; //ProgControl progControl = new ProgControl(); List sourceList = new List(); //public ObservableCollection ItemsList { get; set; } = new ObservableCollection(); string outLinePath; bool IsPlayEnd = false; DateTime? PlayEndTime = null; DirectoryInfo vlcLibDirectory; int curPlayIndex = 0; UCImageText ucimg = new UCImageText(); string ScreenMatch = "拉伸"; //string ScreenMatch = "适应"; Stretch stretch = Stretch.Fill; // Stretch stretch = Stretch.Uniform; List cancellationTokens = new List(); public WindowViewNew(int type = 1) { InitializeComponent(); isShowCountDown = type; this.Width = app.ScreenWidth; this.Height = app.ScreenHeight; outLinePath = AppDomain.CurrentDomain.BaseDirectory + "/OutlineFiles"; pbm = new PlayBackManage(); mh.SetHook(); mh.MouseClickEvent += this_MouseClickDown; try { //Application.ExecutablePathSystem.Windows.Forms.Application.ExecutablePath.Replace("\\", "/").Substring(0, System.Windows.Forms.Application.ExecutablePath.Replace("\\", "/").LastIndexOf("/")) string strImages = System.Environment.CurrentDirectory + "\\pic\\bg.png";//AppDomain.CurrentDomain.BaseDirectory + "pic\\common\\bg.png"; if (File.Exists(strImages) == true) { Uri uri = new Uri(strImages, UriKind.Absolute); ImageBrush ib = new ImageBrush(); ib.ImageSource = new BitmapImage(uri); this.waiting.Background = ib; } } catch (Exception ex) { log.WriteLogFile(ex.ToString(), "WindowViewErrorlog"); } } private void MediaPlayer_EndReached(object sender, Vlc.DotNet.Core.VlcMediaPlayerEndReachedEventArgs e) { //Task.Factory.StartNew(() => { // //this.sourceProvider = null; // Application.Current.Dispatcher.BeginInvoke(new Action(() => { // mainVideo.SourceProvider.MediaPlayer.Play(vlcVideoPath); // })); //}); if (app.isProgramServer) { log.WriteLogFile("发送", "发送"); SendPlay(curPlayIndex); if (!app.isProgramSync) { PlayProg(); } //PlayEnd(media1, media, curIndex); } else if (!app.isProgramSync) { PlayProg(); } //PlayProg(); } //private void MediaPlayer1_EndReached(object sender, Vlc.DotNet.Core.VlcMediaPlayerEndReachedEventArgs e) //{ // //Task.Factory.StartNew(() => { // // //this.sourceProvider = null; // // Application.Current.Dispatcher.BeginInvoke(new Action(() => { // // mainVideo.SourceProvider.MediaPlayer.Play(vlcVideoPath); // // })); // //}); // if (app.isProgramServer) // { // log.WriteLogFile("发送", "发送"); // SendPlay(curPlayIndex); // //PlayEnd(media1, media, curIndex); // } // else if (!app.isProgramSync) // { // PlayProg(); // } // //PlayProg(); //} ///// ///// 修改系统分辨率 ///// ///// 分辨率,单位为毫秒 ///// 返回值 //[DllImport("winmm.dll")] //public static extern uint timeBeginPeriod(int t); ///// ///// 恢复系统分辨率 ///// ///// 分辨率,单位为毫秒 ///// 返回值 //[DllImport("winmm.dll")] //public static extern uint timeEndPeriod(int t); private void LoadScreen(object sender, EventArgs e) { try { jService.GetSyncDev(); } catch (Exception ex) { log.WriteLogFile(ex.Message, "error"); } if (curLoadDate.HasValue && curLoadDate.Value.Date != DateTime.Now.Date) { foreach (var item in sourceList) { if (!item.Token.IsCancellationRequested) { item.Cancel(); item.Dispose(); //item.Dispose(); } } curLoadDate = DateTime.Now; sourceList.Clear(); pbm.DownResource(); //Action action = new Action(() => { GetUControl(); //}); //action.BeginInvoke(null, null); } } private void LoadPics() { try { Storyboard _storyboard = new Storyboard(); for (int i = 0; i < 220; i++) { ObjectAnimationUsingKeyFrames oauf = new ObjectAnimationUsingKeyFrames(); //ObjectAnimationUsingKeyFrames 可以对指定 Duration 内的一组 KeyFrames 中的 Object 属性值进行动画处理 BitmapImage bitmap = new BitmapImage(); bitmap.BeginInit(); string name = i.ToString().PadLeft(5, '0'); bitmap.UriSource = new Uri("pack://application:,,,/Container;component/image/CountDowmImage/倒计时透明度_" + name + ".png"); bitmap.CacheOption = BitmapCacheOption.Default; bitmap.EndInit(); bitmap.Freeze(); ImageBrush imgBrush = new ImageBrush(bitmap); //读取图片文件 DiscreteObjectKeyFrame dokf = new DiscreteObjectKeyFrame(); //DiscreteObjectKeyFrame 通过使用离散内插,可以在前一个关键帧的 Object 值及其自己的 Value 之间进行动画处理。 dokf.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(i * 30)); //KeyTime 获取或设置应到达关键帧的目标 Value 的时间 //这里每隔40毫秒设置一张图片,也就是每秒1000/40=25帧 dokf.Value = imgBrush; imgBrush.Freeze(); oauf.KeyFrames.Add(dokf); dokf.Freeze(); Storyboard.SetTargetProperty(oauf, new PropertyPath("(Rectangle.Fill)")); //把动画应用到窗体的Rectangle中 Storyboard.SetTarget(oauf, RectDisImage); //RectDis是Rectangle的名称 _storyboard.Children.Add(oauf); oauf.Freeze(); //把ObjectAnimationUsingKeyFrames动画添加到Storyboard中 } _storyboard.Completed += new EventHandler(time_Completed); //_storyboard.RepeatBehavior = RepeatBehavior.Forever; _storyboard.Begin(); _storyboard.Freeze(); } catch (Exception ex) { log.WriteLogFile(ex.Message, "error"); } } void time_Completed(object sender, EventArgs e) { timeGrid.Visibility = Visibility.Hidden; gridMain.Visibility = Visibility.Visible; LoadData(); } private void LoadData() { try { //timeBeginPeriod(1); this.EventsRegistion(); // 注册事件 this.LoadScreenTimer.Interval = TimeSpan.FromMinutes(1); //垃圾释放定时器 我定为每十分钟释放一次,大家可根据需要修改 this.LoadProgIsSync.Interval = TimeSpan.FromSeconds(5); this.LoadScreenTimer.Start(); this.LoadProgIsSync.Start(); pbm.DownResource(); WebSocketForProgram.WebSocketReceiveEvent += new WebSocketForProgram.WebSocketReceiveDelegate(WebSocketManage_WebSocketReceiveEvent); JService.ScreenConfigReceiveEvent += new JService.ScreenConfigDelegate(ScreenConfig_ReceiveEvent); //this.GCTimer.Interval = TimeSpan.FromMinutes(30); //垃圾释放定时器 我定为每十分钟释放一次,大家可根据需要修改 //this.GCTimer.Start(); Action action = new Action(() => { jService.GetSyncDev(); jService.SetPlayRecord(); }); action.BeginInvoke(null, null); RectDis.Dispatcher.Invoke(() => { if (app.screensaver.ScreenType == 0 || (app.AppList.Count == 0 && string.IsNullOrEmpty(app.configstartexe))) { _canvas.Visibility = Visibility.Hidden; } else if (app.screensaver.ScreenType < 5) { _canvas.Visibility = Visibility.Visible; RectDis.Visibility = Visibility.Visible; gridImage.Visibility = Visibility.Hidden; LoadPics(app.screensaver.ScreenType); } else if (!string.IsNullOrEmpty(app.screensaver.ScreenFile)) { string fileExtension = System.IO.Path.GetExtension(app.screensaver.ScreenFile); if (fileExtension.ToLower() == ".gif") { _canvas.Visibility = Visibility.Visible; RectDis.Visibility = Visibility.Hidden; gridImage.Visibility = Visibility.Hidden; GifImageLib.GifImage image = new GifImageLib.GifImage(); image.Source = app.screensaver.ScreenFile; image.Width = 300; image.Height = 300; image.Background = new SolidColorBrush(Colors.Transparent); gridmove.Children.Add(image); } else { _canvas.Visibility = Visibility.Visible; RectDis.Visibility = Visibility.Hidden; gridImage.Visibility = Visibility.Visible; Uri uri = new Uri(app.screensaver.ScreenFile, UriKind.Absolute); gridImage.Source = new BitmapImage(uri); } } if (app.screensaver.ScreenEffect == 1) { LoadGif(); if (app.screensaver.EffectType == 0) { gridmove.Margin = new Thickness(0, (_canvas.Height - gridmove.Height) / 2, 0, (_canvas.Height - gridmove.Height) / 2); } } else { if (app.screensaver.EffectType == 0) { gridmove.Margin = new Thickness((_canvas.Width - gridmove.Width), (_canvas.Height - gridmove.Height), 0, 0); } else { gridmove.Margin = new Thickness((_canvas.Width - gridmove.Width) / 2, (_canvas.Height - gridmove.Height) / 2, (_canvas.Width - gridmove.Width) / 2, (_canvas.Height - gridmove.Height) / 2); } } }); StartPlay(); } catch (Exception e) { log.WriteLogFile(e.ToString(), "WindowViewErrorlog"); } } private void WindowView_Load(object sender, RoutedEventArgs e) { //try //{ // var hwndSource = PresentationSource.FromVisual(this) as HwndSource; // var hwndTarget = hwndSource.CompositionTarget; // hwndTarget.RenderMode = RenderMode.SoftwareOnly; //} //catch (Exception ex) //{ // log.WriteLogFile(ex.ToString(), "WinView"); //} try { //LoadScoket(); this.Width = app.ScreenWidth; this.Height = app.ScreenHeight; percentHeight = app.ScreenHeight / 3840; tbMessage.FontSize = 30 * percentHeight; _canvas.Height = 2000 * percentHeight; _canvas.Width = app.ScreenWidth; gridmove.Width = app.ScreenWidth > 1920 ? 600 : 300; gridmove.Height = app.ScreenWidth > 1920 ? 600 : 300; gridImage.Width = app.ScreenWidth > 1920 ? 600 : 300; gridImage.Height = app.ScreenWidth > 1920 ? 600 : 300; RectDis.Width = app.ScreenWidth > 1920 ? 600 : 300; RectDis.Height = app.ScreenWidth > 1920 ? 600 : 300; mainp.Width = app.ScreenWidth; mainp.Height = app.ScreenHeight; //mainVideo.Width = app.ScreenWidth; //mainVideo.Height = app.ScreenHeight; //mainVideo1.Width = app.ScreenWidth; //mainVideo1.Height = app.ScreenHeight; gifPlay.Width = app.ScreenWidth; gifPlay.Height = app.ScreenHeight; mainVideo.Width = app.ScreenWidth; mainVideo.Height = app.ScreenHeight; ShowCursor(0); if (isShowCountDown == 1) { LoadPics(); } else { timeGrid.Visibility = Visibility.Hidden; gridMain.Visibility = Visibility.Visible; LoadData(); } } catch (Exception ex) { log.WriteLogFile(ex.ToString(), "WindowViewErrorlog"); } } private void ScreenConfig_ReceiveEvent() { try { log.WriteLogFile("进来了", "screenconfig1"); foreach (var item in sourceList) { if (!item.Token.IsCancellationRequested) { item.Cancel(); item.Dispose(); } } sourceList.Clear(); GetUControl(); } catch (Exception e) { log.WriteLogFile(e.ToString(), "error"); } } [DllImport("user32.dll", EntryPoint = "ShowCursor", CharSet = CharSet.Auto)] public static extern void ShowCursor(int status); //void OnGarbageCollection(object sender, EventArgs e) //{ // GC.Collect(); // GC.WaitForPendingFinalizers(); // GC.Collect(); //} public void EventsRegistion() { this.LoadScreenTimer.Tick += new EventHandler(LoadScreen); this.LoadProgIsSync.Tick += new EventHandler(LoadProgSync); //this.GCTimer.Tick += new EventHandler(OnGarbageCollection); } public void LoadProgSync(object sender, EventArgs e) { //if (IsPlayEnd && PlayEndTime.HasValue && PlayEndTime.Value.AddSeconds(3) < DateTime.Now) //{ // media.Dispatcher.Invoke(new Action(() => // { // int curIndex = 0; // int zindex = Canvas.GetZIndex(media); // if (zindex == 1) // { // List hashList = videoList.Select(i => i.fileHash).ToList(); // string curUrl = media.Source.ToString(); // string curHash = curUrl.Substring(curUrl.LastIndexOf("/") + 1, curUrl.LastIndexOf(".") - curUrl.LastIndexOf("/") - 1); // if (videoList.Count > 1) // { // curIndex = hashList.ToList().IndexOf(curHash); // if (curIndex + 2 >= videoList.Count) // { // curIndex = curIndex + 2 - videoList.Count; // } // else // { // curIndex = curIndex + 2; // } // } // PlayEnd(media1, media, curIndex); // } // else // { // List hashList = videoList.Select(i => i.fileHash).ToList(); // string curUrl = media1.Source.ToString(); // string curHash = curUrl.Substring(curUrl.LastIndexOf("/") + 1, curUrl.LastIndexOf(".") - curUrl.LastIndexOf("/") - 1); // if (videoList.Count > 1) // { // curIndex = hashList.ToList().IndexOf(curHash); // if (curIndex + 2 >= videoList.Count) // { // curIndex = curIndex + 2 - videoList.Count; // } // else // { // curIndex = curIndex + 2; // } // } // PlayEnd(media, media1, curIndex); // } // })); //} } private void WindowView_Closing(object sender, System.ComponentModel.CancelEventArgs e) { try { log.WriteLogFile("进入关闭屏保" + DateTime.Now.TimeOfDay.ToString(), "closewin"); //timeEndPeriod(1); if (hWaitTimer != IntPtr.Zero) { CloseHandle(hWaitTimer); hWaitTimer = IntPtr.Zero; } log.WriteLogFile("进入关闭屏保1" + DateTime.Now.TimeOfDay.ToString(), "closewin"); if (app.isProgramServer) { app.websocketForProgramServer.CloasSocket(); app.websocketForProgramServer = null; app.isProgramServer = false; app.websocketProgramIP = ""; } log.WriteLogFile("进入关闭屏保2" + DateTime.Now.TimeOfDay.ToString(), "closewin"); if (app.isProgramSync) { app.webSocketForProgram.CloseWebSocket(); app.webSocketForProgram = null; app.isProgramSync = false; app.websocketProgramIP = ""; } log.WriteLogFile("进入关闭屏保3" + DateTime.Now.TimeOfDay.ToString(), "closewin"); //progControl.Dispose(); foreach (var item in sourceList) { if (!item.Token.IsCancellationRequested) { item.Cancel(); item.Dispose(); //item.Dispose(); } } log.WriteLogFile("进入关闭屏保4" + DateTime.Now.TimeOfDay.ToString(), "closewin"); sourceList.Clear(); StopVideo(); log.WriteLogFile("进入关闭屏保5" + DateTime.Now.TimeOfDay.ToString(), "closewin"); foreach (var item in mainVideo.Children) { var mediaClear = (MediaElement)item; mediaClear.Stop(); mediaClear.Close(); } mainVideo.Children.Clear(); log.WriteLogFile("进入关闭屏保6" + DateTime.Now.TimeOfDay.ToString(), "closewin"); FulshMemor(); //if (GCTimer != null) // GCTimer.Stop(); if (LoadScreenTimer != null) LoadScreenTimer.Stop(); log.WriteLogFile("进入关闭屏保7" + DateTime.Now.TimeOfDay.ToString(), "closewin"); mh.UnHook(); log.WriteLogFile("关闭屏保" + DateTime.Now.TimeOfDay.ToString(), "closewin"); //webForFace.CloseWebSocket(); } catch (Exception ex) { log.WriteLogFile("--------" + ex.ToString(), "WindowViewErrorlog"); } try { } catch (Exception ex) { log.WriteLogFile(ex.ToString(), "WindowViewErrorlog"); } } public void FulshMemor() { try { //SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1); //GC.Collect(); //Mouse.OverrideCursor = Cursors.None; } catch { } } [DllImport("kernel32.dll")] public static extern IntPtr CreateWaitableTimer(IntPtr lpTimerAttributes, bool bManualReset, IntPtr lpTimerName); [DllImport("kernel32.dll")] public static extern bool SetWaitableTimer(IntPtr hTimer, ref long pDueTime, long lPeriod, int pfnCompletionRoutine, // TimerCompleteDelegate int lpArgToCompletionRoutine, bool fResume); [DllImport("user32.dll")] public static extern UInt32 MsgWaitForMultipleObjects(uint nCount, ref IntPtr pHandles, bool bWaitAll, int dwMilliseconds, uint dwWakeMask); [DllImport("Kernel32.dll")] public static extern UInt32 WaitForSingleObject(IntPtr pHandles, int dwMilliseconds); [DllImport("kernel32.dll")] public static extern bool CloseHandle(IntPtr hObject); public const int NULL = 0; public const int QS_TIMER = 0x10; public void UsDelay(long us) { long duetime = -1 * us; if (hWaitTimer != IntPtr.Zero) { CloseHandle(hWaitTimer); hWaitTimer = IntPtr.Zero; } if (hWaitTimer == IntPtr.Zero) { hWaitTimer = CreateWaitableTimer(IntPtr.Zero, true, IntPtr.Zero); bool flag = SetWaitableTimer(hWaitTimer, ref duetime, 0, NULL, NULL, false); UInt32 isFlag = WaitForSingleObject(hWaitTimer, Timeout.Infinite); } } /// /// 根据获取到的信息生成UseControl /// private void GetUControl() { try { FulshMemor(); List result = pbm.GetResource(); if (result == null || result.Count == 0) { this.Dispatcher.Invoke(new Action(() => { //if (media.CanPause) // media.Pause(); //if (media1.CanPause) // media1.Pause(); //foreach (var item in mainp.Children) //{ // var mediaClear = (MediaElement)item; // mediaClear.Stop(); // mediaClear.Close(); //} //mainp.Children.Clear(); foreach (var item in sourceList) { if (!item.Token.IsCancellationRequested) { item.Cancel(); item.Dispose(); //item.Dispose(); } } sourceList.Clear(); foreach (var item in mainVideo.Children) { var mediaClear = (MediaElement)item; mediaClear.Stop(); mediaClear.Close(); } mainVideo.Children.Clear(); //progControl.Dispose(); StopVideo(); mainp.Visibility = Visibility.Hidden; waiting.Visibility = Visibility.Visible; })); return; } else { this.Dispatcher.Invoke(new Action(() => { foreach (var item in sourceList) { if (!item.Token.IsCancellationRequested) { item.Cancel(); item.Dispose(); //item.Dispose(); } } sourceList.Clear(); foreach (var item in mainVideo.Children) { var mediaClear = (MediaElement)item; mediaClear.Stop(); mediaClear.Close(); } mainVideo.Children.Clear(); StopVideo(); mainp.Visibility = Visibility.Visible; waiting.Visibility = Visibility.Hidden; })); } if (hWaitTimer != IntPtr.Zero) { CloseHandle(hWaitTimer); hWaitTimer = IntPtr.Zero; } LoadScheduler(result); } catch (Exception ex) { log.WriteLogFile(ex.ToString(), "WindowViewErrorlog"); } } [DllImport("kernel32.dll", EntryPoint = "SetProcessWorkingSetSize")] public static extern int SetProcessWorkingSetSize(IntPtr process, int minSize, int maxSize); private bool LoadScheduler(List progList) { bool isScheduler = false; if (hWaitTimer != IntPtr.Zero) { CloseHandle(hWaitTimer); hWaitTimer = IntPtr.Zero; } try { progList = progList.Where(i => Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " " + i.endTime) > DateTime.Now).OrderBy(i => i.beginTime).ToList(); if (progList != null && progList.Count > 0) { if (Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " " + progList[0].beginTime) <= DateTime.Now) { PlayScheduler(progList[0]); Action action = new Action(() => { var curDate = DateTime.Now; var stopTime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " " + progList[0].endTime); UsDelay((stopTime.Ticks - curDate.Ticks)); if (hWaitTimer != IntPtr.Zero) { CloseHandle(hWaitTimer); hWaitTimer = IntPtr.Zero; } LoadScheduler(progList); }); action.BeginInvoke(null, null); } else { app.currentIndex = -1; Action action = new Action(() => { var curDate = DateTime.Now; var stopTime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " " + progList[0].beginTime); UsDelay((stopTime.Ticks - curDate.Ticks)); if (hWaitTimer != IntPtr.Zero) { CloseHandle(hWaitTimer); hWaitTimer = IntPtr.Zero; } PlayScheduler(progList[0]); Action action1 = new Action(() => { curDate = DateTime.Now; stopTime = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " " + progList[0].endTime); if (hWaitTimer != IntPtr.Zero) { CloseHandle(hWaitTimer); hWaitTimer = IntPtr.Zero; } curDate = DateTime.Now; UsDelay((stopTime.Ticks - curDate.Ticks)); LoadScheduler(progList); }); action1.BeginInvoke(null, null); }); action.BeginInvoke(null, null); this.Dispatcher.Invoke(new Action(() => { //if(media.CanPause) //media.Pause(); //if (media1.CanPause) // media1.Pause(); //foreach (var item in mainp.Children) //{ // var mediaClear = (MediaElement)item; // mediaClear.Stop(); // mediaClear.Close(); //} //mainp.Children.Clear(); //progControl.Dispose(); foreach (var item in sourceList) { if (!item.Token.IsCancellationRequested) { item.Cancel(); item.Dispose(); //item.Dispose(); } } sourceList.Clear(); foreach (var item in mainVideo.Children) { var mediaClear = (MediaElement)item; mediaClear.Stop(); mediaClear.Close(); } mainVideo.Children.Clear(); StopVideo(); mainp.Visibility = Visibility.Hidden; waiting.Visibility = Visibility.Visible; })); } } else { this.Dispatcher.Invoke(new Action(() => { foreach (var item in sourceList) { if (!item.Token.IsCancellationRequested) { item.Cancel(); item.Dispose(); } } sourceList.Clear(); //if (media.CanPause) // media.Pause(); //if (media1.CanPause) // media1.Pause(); foreach (var item in mainVideo.Children) { var mediaClear = (MediaElement)item; mediaClear.Stop(); mediaClear.Close(); } mainVideo.Children.Clear(); StopVideo(); //progControl.Dispose(); mainp.Visibility = Visibility.Hidden; waiting.Visibility = Visibility.Visible; })); } } catch (Exception e) { log.WriteLogFile(e.ToString()); } return isScheduler; } //private async void PlayScheduler(ProgModel scheduler) //{ // try // { // //Task tsk1 = factory.StartNew(() => // //{ // foreach (var item in sourceList) // { // if (!item.Token.IsCancellationRequested) // { // item.Cancel(); // item.Dispose(); // } // } // sourceList.Clear(); // Transition transition = CommonMethod.GetTransition("渐入"); // if (scheduler != null && scheduler.programs != null && scheduler.programs.Count > 0) // { // this.Dispatcher.Invoke(new Action(() => // { // mainp.Visibility = Visibility.Visible; // waiting.Visibility = Visibility.Hidden; // })); // var playIndex = 0; // CancellationTokenSource source1 = new CancellationTokenSource(); // sourceList.Add(source1); // while (true) // { // if (source1.Token.IsCancellationRequested) // { // //isStop = true; // // 释放资源操作等等... // break; // } // //if (!curDate.HasValue || curDate.Value.AddMilliseconds(duration) <= DateTime.Now) // //{ // var item = scheduler.programs[playIndex]; // this.Dispatcher.Invoke(new Action(() => // { // progControl.Dispose(); // progControl.LoadProg(this.Width, this.Height, item.backgroundMaterialInfo, item.backgroundColor, item.components); // mainp.Content = progControl; // playIndex++; // if (playIndex >= scheduler.programs.Count) // { // playIndex = 0; // } // })); // TimeSpan.TryParse(item.duration, out TimeSpan timeSpan); // if (source1.Token.IsCancellationRequested) // { // break; // } // else // { // try // { // await Task.Delay(Convert.ToInt32(timeSpan.TotalMilliseconds), source1.Token); // } // catch (Exception) // { // break; // } // } // //await Task.Delay(Convert.ToInt32(timeSpan.TotalMilliseconds), source1.Token); // //} // //else // //{ // // Task.Delay(10,token); // //} // } // } // else // { // this.Dispatcher.Invoke(new Action(() => // { // mainp.Visibility = Visibility.Hidden; // waiting.Visibility = Visibility.Visible; // })); // } // //}); // } // catch (Exception e) // { // log.WriteLogFile(e.ToString()); // } //} private async void PlayScheduler(ProgModel scheduler) { try { //Task tsk1 = factory.StartNew(() => //{ log.WriteLogFile(JsonConvert.SerializeObject(scheduler), "22222"); try { foreach (var item in sourceList) { if (!item.Token.IsCancellationRequested) { item.Cancel(); item.Dispose(); } } sourceList.Clear(); log.WriteLogFile("取消定时", "token"); } catch (Exception e) { log.WriteLogFile(e.ToString(), "PlaySchedulerError"); } if (scheduler != null && scheduler.programs != null && scheduler.programs.Count > 0) { this.Dispatcher.Invoke(new Action(() => { mainp.Visibility = Visibility.Visible; waiting.Visibility = Visibility.Hidden; })); //var videoList= scheduler.programs.Where(i=>i.components.).Select(i=>i.components) List videoNow = new List(); string backCorlor = string.Empty; foreach (var item in scheduler.programs) { var videoProg = item.components.Where(i => i.typeCode == "video" || i.typeCode == "image").OrderBy(i => i.zIndex).ToList(); foreach (var itemVideo in videoProg) { videoNow.AddRange(itemVideo.materials.OrderBy(i => i.order).Select(i => new PlayMaterial { duration = i.duration, fileHash = i.fileHash, fileUrl = i.fileUrl, materialCode = i.materialCode, name = i.name, order = i.order, mediaInfo = i.mediaInfo, config = itemVideo.config, typeCode = itemVideo.typeCode }).ToList()); } if (string.IsNullOrEmpty(item.backgroundColor)) { backCorlor = item.backgroundColor; } } if (!string.IsNullOrEmpty(backCorlor)) { Color color = (Color)ColorConverter.ConvertFromString(backCorlor); mainp.Background = new SolidColorBrush(color); } videoList.Clear(); videoList.AddRange(videoNow); if (videoList.Count > 0) { log.WriteLogFile("进入", "222"); this.Dispatcher.Invoke(new Action(() => { //if (media.CanPause) //{ // media.Pause(); //} //if (media1.CanPause) //{ // media1.Pause(); //} foreach (var item in mainVideo.Children) { var mediaClear = (MediaElement)item; mediaClear.Stop(); mediaClear.Close(); } mainVideo.Children.Clear(); StopVideo(); curPlayIndex = 0; PlayProg(); //if (app.isProgramServer) //{ // log.WriteLogFile("发送", "发送"); // SendPlay(curPlayIndex); // //PlayEnd(media1, media, curIndex); //} //else if (!app.isProgramSync) //{ // PlayProg(); //} //mainVideo.SourceProvider.MediaPlayer.Pause(); mainp.Visibility = Visibility.Visible; waiting.Visibility = Visibility.Hidden; })); } else { this.Dispatcher.Invoke(new Action(() => { foreach (var item in mainVideo.Children) { var mediaClear = (MediaElement)item; mediaClear.Stop(); mediaClear.Close(); } mainVideo.Children.Clear(); StopVideo(); //mainVideo.SourceProvider.MediaPlayer.Pause(); curPlayIndex = 0; //PlayProg(); mainp.Visibility = Visibility.Hidden; waiting.Visibility = Visibility.Visible; })); } } else { this.Dispatcher.Invoke(new Action(() => { foreach (var item in mainVideo.Children) { var mediaClear = (MediaElement)item; mediaClear.Stop(); mediaClear.Close(); } mainVideo.Children.Clear(); mainp.Visibility = Visibility.Hidden; waiting.Visibility = Visibility.Visible; })); } //}); } catch (Exception e) { log.WriteLogFile(e.ToString()); } } private void PlayProg() { try { if (videoList.Count == 0) { log.WriteLogFile("进来了", "token"); return; } if (curPlayIndex >= videoList.Count) { curPlayIndex = 0; } Transition transition = CommonMethod.GetTransition("渐入"); string fileExtension = string.Empty; string url = string.Empty; foreach (var item in sourceList) { if (!item.Token.IsCancellationRequested) { item.Cancel(); item.Dispose(); } } sourceList.Clear(); if (videoList[curPlayIndex].fileUrl.Contains("?")) { fileExtension = videoList[curPlayIndex].fileUrl.Substring(videoList[curPlayIndex].fileUrl.LastIndexOf("."), videoList[curPlayIndex].fileUrl.LastIndexOf("?") - videoList[curPlayIndex].fileUrl.LastIndexOf(".")).ToLower(); } else { fileExtension = videoList[curPlayIndex].fileUrl.Substring(videoList[curPlayIndex].fileUrl.LastIndexOf(".")).ToLower(); } url = outLinePath + "/Main/" + videoList[curPlayIndex].fileHash + fileExtension; log.WriteLogFile(url, "file"); var ext = fileExtension.ToLower().Split('.').Last(); FileTypeJudgment fvdo = new FileTypeJudgment() { TypeTarget = new TypeVideo() }; log.WriteLogFile(fileExtension.ToLower(), "file"); log.WriteLogFile(fvdo.Judge(ext).ToString(), "file"); if (fvdo.Judge(ext)) { StartVideo(url, videoList[curPlayIndex].fileHash); } else { if (mainVideo.Visibility == Visibility.Visible) { this.Dispatcher.Invoke(() => { mainVideo.Visibility = Visibility.Hidden; }); } PlayImage(videoList[curPlayIndex], url); } } catch (Exception e) { log.WriteLogFile("---" + e.ToString(), "333"); if (e.ToString().Contains("指定的参数已超出有效值的范围")) { this.Dispatcher.Invoke(() => { app.main.WinView = this; }); } else { ScreenConfig_ReceiveEvent(); } //await Task.Delay(new TimeSpan(0,0,0,1)); //Thread.Sleep(1000); //PlayProg(); } } private async void StartVideo(string videoPath, string fileHash) { try { this.Dispatcher.Invoke(() => { mainImage.Visibility = Visibility.Hidden; }); if (mainVideo.Visibility == Visibility.Hidden) { this.Dispatcher.Invoke(() => { mainVideo.Visibility = Visibility.Visible; }); } mainVideo.Dispatcher.Invoke(() => { mainVideo.Children.Clear(); MediaElement media = new MediaElement(); //media.Dispatcher.Invoke(new Action(() => //{ media.LoadedBehavior = MediaState.Manual; media.Stretch = stretch; media.Width = app.ScreenWidth; media.Height = app.ScreenHeight; media.Source = new Uri(videoPath); media.MediaEnded += media_MediaEnded; media.Play(); mainVideo.Children.Add(media); }); } catch (Exception e) { log.WriteLogFile(e.ToString(), "videoError"); } //try //{ // Task.Factory.StartNew(() => { // if (mainVideo.Visibility == Visibility.Visible) { // mainVideo.SourceProvider.MediaPlayer.Pause(); // mainVideo1.SourceProvider.MediaPlayer.Play(new Uri(videoPath)); // } else { // if (mainVideo1.Visibility == Visibility.Visible) // { // mainVideo1.SourceProvider.MediaPlayer.Pause(); // } // mainVideo.SourceProvider.MediaPlayer.Play(new Uri(videoPath)); // } // }); //} //catch (Exception ex) //{ // log.WriteLogFile(videoPath + ex.ToString(), "StopVideoError"); //} } private void seeyou(MediaElement mep) { //bool isseeyou = true; //double allTime = 0; //int index = curPlayIndex; //string x = ""; //string y = ""; //string isseeyous = mep?.Position.ToString(); //log.WriteLogFile("开始时长" + isseeyous, "seeyou"); //int t = 0; //Task ta = new Task(() => //{ // while (isseeyou && index == curPlayIndex) // { // try // { // Thread.Sleep(1000); // if (string.IsNullOrEmpty(x)) // { // Thread.Sleep(1000); // try // { // this.Dispatcher.Invoke(() => // { // if (mep.NaturalDuration.HasTimeSpan) // { // x = mep?.NaturalDuration.TimeSpan.ToString(); // allTime = mep.NaturalDuration.TimeSpan.TotalSeconds; // log.WriteLogFile("总时长秒:" + allTime, "seeyou"); // } // } // ); // log.WriteLogFile("总时长:" + x, "seeyou"); // } // catch (Exception ex) // { // log.WriteLogFile(ex.ToString(), "seeyou"); // } // } // this.Dispatcher.Invoke(() => // { // try // { // y = mep?.Position.ToString(); // } // catch (Exception ex) // { // y = y + "0"; // log.WriteLogFile(ex.ToString(), "seeyou"); // } // }); // if (isseeyous.Equals(y)) // { // log.WriteLogFile("没在播" + Environment.NewLine + isseeyous + Environment.NewLine + y, "seeyou"); // t++; // } // else // { // if (t != 0) // { // t = 0; // } // log.WriteLogFile("正常播呢", "seeyous"); // isseeyous = y; // } // //C#中的TimeSpan.Compare()方法用于比较两个TimeSpan值,并返回一个整数,该整数指示第一个值是小于,等于还是大于第二个值。 // //如果span1小于span2,则返回值为 - 1;如果span1 = span2,则返回值为0;如果span1大于span2,则返回值为1。 // try // { // log.WriteLogFile(mep.Position.TotalSeconds.ToString(), "CountTe"); // } // catch (Exception ex) // { // log.WriteLogFile(ex.ToString(), "seeyou"); // } // if (!string.IsNullOrEmpty(x) && !(allTime > mep.Position.TotalSeconds)) // { // log.WriteLogFile("播完了", "seeyous"); // isseeyou = false; ; // } // if (t > 2 && isseeyou && curPlayIndex == index && !string.IsNullOrEmpty(x)) // { // isseeyou = false; // log.WriteLogFile("异常了,准备关了重开" + Environment.NewLine + x + Environment.NewLine + y, "seeyouErr"); // this.Dispatcher.Invoke(() => // { // app.main.WinView = this; // }); // } // } // catch (Exception ex) // { // log.WriteLogFile(ex.ToString(), "seeyou"); // } // } //}); //ta.Start(); } private void StopVideo() { //try //{ // //myControl.SourceProvider.MediaPlayer.Pause(); // //this.myControl.Dispose(); // if (mainVideo.SourceProvider.MediaPlayer.IsPlaying()) { // mainVideo.SourceProvider.MediaPlayer.Pause(); // } // if (mainVideo1.SourceProvider.MediaPlayer.IsPlaying()) // { // mainVideo1.SourceProvider.MediaPlayer.Pause(); // } //} //catch (Exception e) //{ // //log.WriteLogFile(videoUrl + e.ToString(), "StopVideoError"); //} } private void PlayImage(PlayMaterial material, string url) { try { log.WriteLogFile("播放111", "file"); CancellationTokenSource source1 = new CancellationTokenSource(); sourceList.Add(source1); CancellationToken token = source1.Token; TaskFactory factory = new TaskFactory(token); Task tsk1 = factory.StartNew(async () => { log.WriteLogFile("播放12222", "file"); try { var transitionPeriod = material.config.Value("transitionPeriod"); var transition = material.config.Value("transition"); string fileExtension = string.Empty; if (fileExtension.ToLower() == ".gif") { GC.Collect(); mainImage.Dispatcher.Invoke(new Action(() => { FileStream s = new FileStream(url, FileMode.Open, FileAccess.Read); // XamlAnimatedGif.AnimationBehavior.SetSourceUri(gifPlay, new Uri(outLinePath + "/Main/" + ucList[app.currentIndex].sourceId + fileExtension)); XamlAnimatedGif.AnimationBehavior.SetSourceStream(gifPlay, s); XamlAnimatedGif.AnimationBehavior.SetRepeatBehavior(gifPlay, RepeatBehavior.Forever); XamlAnimatedGif.AnimationBehavior.SetAutoStart(gifPlay, true); gifPlay.Visibility = Visibility.Visible; mainImage.Visibility = Visibility.Hidden; mainVideo.Visibility = Visibility.Hidden; //mainVideo1.Visibility = Visibility.Hidden; })); } else { mainImage.Dispatcher.Invoke(new Action(() => { ucimg.LoadData(this.Width, this.Height, url, "", ScreenMatch); mainImage.Content = ucimg; mainVideo.Visibility = Visibility.Hidden; // mainVideo1.Visibility = Visibility.Hidden; gifPlay.Visibility = Visibility.Hidden; mainImage.Visibility = Visibility.Visible; log.WriteLogFile("播放", "file"); })); } await Task.Delay(transitionPeriod * 1000, token); log.WriteLogFile(token.IsCancellationRequested.ToString(), "token"); if (!token.IsCancellationRequested) { if (app.isProgramServer) { log.WriteLogFile("发送", "发送"); curPlayIndex++; SendPlay(curPlayIndex); if (!app.isProgramSync) { PlayProg(); } //PlayEnd(media1, media, curIndex); } else if (!app.isProgramSync) { curPlayIndex++; PlayProg(); } } } catch (Exception e) { log.WriteLogFile("---" + e.ToString(), "fileerror"); } }); } catch (Exception e) { log.WriteLogFile(e.ToString(), "fileerror"); } } private void BindImage(Image image, string img, string transition) { Action action = new Action(() => { image.Dispatcher.Invoke(new Action(() => { if (img.ToLower().EndsWith(".gif")) { //FileStream stream = new FileStream(img, FileMode.Open, FileAccess.Read); //XamlAnimatedGif.AnimationBehavior.SetSourceStream(image, stream); //FileStream s = new FileStream(outLinePath + "/Main/" + ucList[app.currentIndex].sourceId + fileExtension, FileMode.Open, FileAccess.Read); XamlAnimatedGif.AnimationBehavior.SetSourceUri(image, new Uri(img)); XamlAnimatedGif.AnimationBehavior.SetRepeatBehavior(image, RepeatBehavior.Forever); XamlAnimatedGif.AnimationBehavior.SetAutoStart(image, true); } else { image.Source = new BitmapImage(new Uri(img)); } })); }); action.BeginInvoke(null, null); } /// /// 开始播放 /// private void StartPlay() { curLoadDate = DateTime.Now; GetUControl(); } private void this_MouseClickDown(object sender, System.Windows.Forms.MouseEventArgs e) { try { if (e.Button == System.Windows.Forms.MouseButtons.Left) //|| e.Button == System.Windows.Forms.MouseButtons.Right { //点击翻页 //Point p = new Point(e.Location.X, e.Location.Y); //if (p.X < this.Width / 2) //{ // app.currentIndex -= 2; // while (app.currentIndex < 0) // { // app.currentIndex = ucList.Count + app.currentIndex; // } //} //if (isMedia) //{ // isMedia = false; // SetProcessWorkingSetSize(Process.GetCurrentProcess().Handle, -1, -1); //} //else //{ // ImageShowTime = 0; //} //------------------ //点击关闭 Point p = new Point(e.Location.X, e.Location.Y); Points.Add(p); if (Points.Count == 5) Points.Remove(Points[0]); if (Points.Count > 4) Points.Clear(); else if (Points.Count == 4 && p.X < 100 && p.Y > this.Height - 100) { p = (Point)Points[2]; if (p.X < 100 && p.Y > this.Height - 100) { p = (Point)Points[1]; if (p.X < 100 && p.Y > this.Height - 100) { p = (Point)Points[0]; if (p.X < 100 && p.Y > this.Height - 100) { this.Close(); } } } } //------------------ } //Mouse.OverrideCursor = Cursors.Arrow; } catch (Exception ex) { Class_Log log = new Class_Log(); log.WriteLogFile("记录鼠标位置异常" + ex.ToString(), "MainWindowErrorLog"); } } private void LoadPics(int type) { try { Storyboard _storyboard = new Storyboard(); int count = 99; if (type < 3) { count = 68; } for (int i = 0; i < count; i++) { ObjectAnimationUsingKeyFrames oauf = new ObjectAnimationUsingKeyFrames(); //ObjectAnimationUsingKeyFrames 可以对指定 Duration 内的一组 KeyFrames 中的 Object 属性值进行动画处理 BitmapImage bitmap = new BitmapImage(); bitmap.BeginInit(); string name = i.ToString().PadLeft(5, '0'); bitmap.UriSource = new Uri("pack://application:,,,/Container;component/touch/touch" + type + "/touch_" + name + ".png"); log.WriteLogFile(bitmap.UriSource.AbsolutePath, "file"); bitmap.CacheOption = BitmapCacheOption.Default; bitmap.EndInit(); bitmap.Freeze(); ImageBrush imgBrush = new ImageBrush(bitmap); //读取图片文件 DiscreteObjectKeyFrame dokf = new DiscreteObjectKeyFrame(); //DiscreteObjectKeyFrame 通过使用离散内插,可以在前一个关键帧的 Object 值及其自己的 Value 之间进行动画处理。 dokf.KeyTime = KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(i * 30)); //KeyTime 获取或设置应到达关键帧的目标 Value 的时间 //这里每隔40毫秒设置一张图片,也就是每秒1000/40=25帧 dokf.Value = imgBrush; imgBrush.Freeze(); oauf.KeyFrames.Add(dokf); dokf.Freeze(); Storyboard.SetTargetProperty(oauf, new PropertyPath("(Rectangle.Fill)")); //把动画应用到窗体的Rectangle中 Storyboard.SetTarget(oauf, RectDis); //RectDis是Rectangle的名称 _storyboard.Children.Add(oauf); oauf.Freeze(); //把ObjectAnimationUsingKeyFrames动画添加到Storyboard中 } _storyboard.RepeatBehavior = RepeatBehavior.Forever; _storyboard.Begin(); _storyboard.Freeze(); } catch (Exception ex) { log.WriteLogFile(ex.Message, "error"); } } private void LoadGif() { endX = _canvas.Width - gridmove.Width; Random ran = new Random(); endY = ran.Next(0, Convert.ToInt32(_canvas.Height - gridmove.Height)); ; ss(); } void ss_Completed(object sender, EventArgs e) { Random ran = new Random(); beginX = endX; beginY = endY; if (app.screensaver.EffectType == 1) { if (endX >= _canvas.Width - gridmove.Width) { if (endY >= (_canvas.Height - gridmove.Width) / 2) { endX = ran.Next(0, Convert.ToInt32((_canvas.Width - gridmove.Width) / 2)); endY = _canvas.Height - gridmove.Height; } else { endX = ran.Next(0, Convert.ToInt32((_canvas.Width - gridmove.Width) / 2)); endY = 0; } } else if (endX == 0) { if (endY >= (_canvas.Height - gridmove.Height) / 2) { endX = ran.Next(Convert.ToInt32((_canvas.Width - gridmove.Width) / 2), Convert.ToInt32(_canvas.Width - gridmove.Width)); endY = 0; } else { endX = ran.Next(Convert.ToInt32((_canvas.Width - gridmove.Width) / 2), Convert.ToInt32(_canvas.Width - gridmove.Width)); endY = _canvas.Height - gridmove.Height; } } else if (endY == _canvas.Height - gridmove.Height) { if (endX >= (_canvas.Width - gridmove.Width) / 2) { endY = ran.Next(0, Convert.ToInt32((_canvas.Height - gridmove.Height) / 2)); endX = _canvas.Width - gridmove.Width; } else { endY = ran.Next(0, Convert.ToInt32((_canvas.Height - gridmove.Height) / 2)); endX = 0; } } else if (endY == 0) { if (endX >= (_canvas.Width - gridmove.Width) / 2) { endY = ran.Next(Convert.ToInt32((_canvas.Height - gridmove.Height) / 2), Convert.ToInt32(_canvas.Height - gridmove.Height)); endX = _canvas.Width - gridmove.Width; } else { endY = ran.Next(Convert.ToInt32((_canvas.Height - gridmove.Height) / 2), Convert.ToInt32(_canvas.Height - gridmove.Height)); endX = 0; } } } else { if (beginX == 0) { endX = _canvas.Width - gridmove.Width; } else { endX = 0; } } ss(); } void ss() { var x = endX - beginX; var y = endY - beginY; var z = Math.Sqrt(x * x + y * y); var time = z / 200; DoubleAnimation DAnimation = new DoubleAnimation(); DAnimation.From = beginX;//起点 DAnimation.To = endX;//终点 DAnimation.Duration = new Duration(TimeSpan.FromSeconds(time));//时间 Storyboard.SetTarget(DAnimation, gridmove); Storyboard.SetTargetProperty(DAnimation, new PropertyPath(Canvas.LeftProperty)); Storyboard story = new Storyboard(); story.Completed += new EventHandler(ss_Completed);//完成后要做的事 //story.RepeatBehavior = RepeatBehavior.Forever;//无限次循环,需要的自己加上 if (app.screensaver.EffectType == 1) { DoubleAnimation DAnimation1 = new DoubleAnimation(); DAnimation1.From = beginY;//起点 DAnimation1.To = endY;//终点 DAnimation1.Duration = new Duration(TimeSpan.FromSeconds(time));//时间 Storyboard.SetTarget(DAnimation1, gridmove); Storyboard.SetTargetProperty(DAnimation1, new PropertyPath(Canvas.TopProperty)); story.Children.Add(DAnimation1); } story.Children.Add(DAnimation); DAnimation.Freeze(); story.Begin(); story.Freeze(); } private void media_MediaEnded(object sender, RoutedEventArgs e) { //MediaElement media = (MediaElement)sender; //int curIndex = 0; //List hashList = videoList.Select(i => i.fileHash).ToList(); //string curUrl = media.Source.ToString(); //string curHash = curUrl.Substring(curUrl.LastIndexOf("/") + 1, curUrl.LastIndexOf(".") - curUrl.LastIndexOf("/") - 1); //if (videoList.Count > 1) //{ // curIndex = hashList.ToList().IndexOf(curHash); // if (curIndex + 2 >= videoList.Count) // { // curIndex = curIndex + 2 - videoList.Count; // } // else // { // curIndex = curIndex + 2; // } //} if (app.isProgramServer) { curPlayIndex++; log.WriteLogFile("发送", "发送"); SendPlay(curPlayIndex); if (!app.isProgramSync) { PlayProg(); } //PlayEnd(media1, media, curIndex); } else if (!app.isProgramSync) { curPlayIndex++; PlayProg(); // PlayEnd((MediaElement)mainp.Children[mainp.Children.Count-1], (MediaElement)mainp.Children[mainp.Children.Count - 2], curIndex); } else { IsPlayEnd = true; PlayEndTime = DateTime.Now; } } //private void media1_MediaEnded(object sender, RoutedEventArgs e) //{ // //string fileExtensionCur = string.Empty; // //string urlCur = string.Empty; // //List hashList = videoList.Select(i => i.fileHash).ToList(); // //string curUrl = media1.Source.ToString(); // //string curHash = curUrl.Substring(curUrl.LastIndexOf("/") + 1, curUrl.LastIndexOf(".") - curUrl.LastIndexOf("/") - 1); // //var curIndex = 0; // //if (videoList.Count > 1) // //{ // // curIndex = hashList.ToList().IndexOf(curHash); // // if (curIndex + 2 >= videoList.Count) // // { // // curIndex = curIndex + 2 - videoList.Count; // // } // // else // // { // // curIndex = curIndex + 2; // // } // //} // ////if (curIndex >= item.materials.Count) // ////{ // //// curIndex = 0; // ////} // //if (videoList[curIndex].fileUrl.Contains("?")) // //{ // // fileExtensionCur = videoList[curIndex].fileUrl.Substring(videoList[curIndex].fileUrl.LastIndexOf("."), videoList[curIndex].fileUrl.LastIndexOf("?") - videoList[curIndex].fileUrl.LastIndexOf(".")).ToLower(); // //} // //else // //{ // // fileExtensionCur = videoList[curIndex].fileUrl.Substring(videoList[curIndex].fileUrl.LastIndexOf(".")).ToLower(); // //} // //urlCur = outLinePath + "/Main/" + videoList[curIndex].fileHash + fileExtensionCur; // //media1.Play(); // //media.Play(); // //Thread.Sleep(500); // //Canvas.SetZIndex(media, 2); // //Canvas.SetZIndex(media1, 0); // //Canvas.SetZIndex(media, 1); // //media1.Source = new Uri(urlCur); // //media1.Play(); // //media1.Pause(); // int curIndex = 0; // List hashList = videoList.Select(i => i.fileHash).ToList(); // string curUrl = media1.Source.ToString(); // string curHash = curUrl.Substring(curUrl.LastIndexOf("/") + 1, curUrl.LastIndexOf(".") - curUrl.LastIndexOf("/") - 1); // if (videoList.Count > 1) // { // curIndex = hashList.ToList().IndexOf(curHash); // if (curIndex + 2 >= videoList.Count) // { // curIndex = curIndex + 2 - videoList.Count; // } // else // { // curIndex = curIndex + 2; // } // } // if (app.isProgramServer) // { // log.WriteLogFile("fas", "发送"); // //PlayEnd(media, media1, curIndex); // SendPlay(curIndex); // } // else if (!app.isProgramSync) // { // PlayEnd(media, media1, curIndex); // } // else // { // IsPlayEnd = true; // PlayEndTime = DateTime.Now; // } //} private void SendPlay(int curIndex) { app.isSendSync = true; try { log.WriteLogFile(WebsocketForProgramServer.allSockets.ToList().ToString() + " " + curIndex, "发送"); WebsocketForProgramServer.allSockets.ToList().ForEach(s => s.Send(curIndex.ToString())); } catch (Exception e) { log.WriteLogFile(e.ToString(), "StartPlayerror"); } } private void WebSocketManage_WebSocketReceiveEvent(string type, string message) { try { log.WriteLogFile(message, "WebSocketLogProg"); if (type == "play") { int curIndex = Convert.ToInt32(message); if (curIndex >= videoList.Count) { curIndex = 0; } //if (!app.isProgramServer) //{ curPlayIndex = curIndex; mainp.Dispatcher.Invoke(new Action(() => { foreach (var item in mainVideo.Children) { var videoPlay = (MediaElement)item; if (videoPlay.CanPause) { videoPlay.Pause(); } } PlayProg(); })); //} } //else if (type == "close") { // media.Dispatcher.Invoke(new Action(() => // { // int curIndex = 0; // int zindex = Canvas.GetZIndex(media); // if (zindex == 1) // { // List hashList = videoList.Select(i => i.fileHash).ToList(); // string curUrl = media.Source.ToString(); // string curHash = curUrl.Substring(curUrl.LastIndexOf("/") + 1, curUrl.LastIndexOf(".") - curUrl.LastIndexOf("/") - 1); // if (videoList.Count > 1) // { // curIndex = hashList.ToList().IndexOf(curHash); // if (curIndex + 2 >= videoList.Count) // { // curIndex = curIndex + 2 - videoList.Count; // } // else // { // curIndex = curIndex + 2; // } // } // PlayEnd(media1, media, curIndex); // } // else // { // List hashList = videoList.Select(i => i.fileHash).ToList(); // string curUrl = media1.Source.ToString(); // string curHash = curUrl.Substring(curUrl.LastIndexOf("/") + 1, curUrl.LastIndexOf(".") - curUrl.LastIndexOf("/") - 1); // if (videoList.Count > 1) // { // curIndex = hashList.ToList().IndexOf(curHash); // if (curIndex + 2 >= videoList.Count) // { // curIndex = curIndex + 2 - videoList.Count; // } // else // { // curIndex = curIndex + 2; // } // } // PlayEnd(media, media1, curIndex); // } // })); //} } catch (Exception ex) { log.WriteLogFile(ex.ToString(), "errorsocket"); } } private void Window_MouseDown(object sender, MouseButtonEventArgs e) { try { log.WriteLogFile("点击屏保,进入关闭屏保方法" + DateTime.Now.TimeOfDay.ToString(), "closewin"); if (!string.IsNullOrEmpty(app.configstartexe)) { app.isStartScreen = false; //关闭信息发布 //Process[] pro = Process.GetProcesses(); //for (int i = 0; i < pro.Length; i++) //{ // if (pro[i].ProcessName.ToLower().Trim() == "pcscreensavers") // { // pro[i].Kill();//结束进程 // } //} app.AppPlayNameCH = "导视"; app.Appversion = app.kioskVersion; app.AppPlayName = "chrome"; app.CurAppPlayName = app.AppPlayName; WebSocketForKiosk.allSocketsForKiosk.ToList().ForEach(s => s.Send("kiosk")); //webForFace.CloseWebSocket(); FulshMemor(); if (hWaitTimer != IntPtr.Zero) { CloseHandle(hWaitTimer); hWaitTimer = IntPtr.Zero; } //source1.Cancel(); //source1.Dispose(); this.Dispatcher.Invoke((Action)(() => { this.Close(); })); } } catch (Exception ex) { log.WriteLogFile(ex.ToString()); } } //private void media1_MediaFailed(object sender, ExceptionRoutedEventArgs e) //{ // log.WriteLogFile("卡了1", "mediaerror"); // //media1.Close(); // media1.Dispatcher.Invoke(new Action(() => // { // media1.Stop(); // media1.Position = new TimeSpan(0,0,0,0,100); // media1.Play(); // })); //} //private void media_MediaFailed(object sender, ExceptionRoutedEventArgs e) //{ // log.WriteLogFile("卡了", "mediaerror"); // media.Dispatcher.Invoke(new Action(() => // { // media.Stop(); // media.Position = new TimeSpan(0, 0, 0, 0, 100); // media.Play(); // })); //} } }