void InitPlayer(AbnormalViewModel p) { string folderPath = p.Meta.FramePath; Player = new PlayerModel { Target = Convert.ToInt32(p.Abnormal.Position)//目标帧号 }; try { DirectoryInfo root = new DirectoryInfo(folderPath); FileInfo[] files = root.GetFiles("*.jpg"); files = files.OrderBy(y => y.Name, new FileComparer()).ToArray(); foreach (var item in files) { string name = item.FullName; imagePath.Add(name); } Player.Calculate(imagePath.Count); } catch (PathTooLongException) { MessageBox.Show("文件路径过长"); } catch (ArgumentException) { MessageBox.Show("该路径下文件错误"); } catch (Exception e) { MessageBox.Show("发生异常:" + e.ToString()); } }
private void ExecuteSelectCommand(AbnormalViewModel p) { stop = true; //tokenSource.Cancel(); //更新左下角显示区域 SelectedAVM = p; CombboxItem = CombboxList[p.Abnormal.Type]; //播放视频 //找到文件 string folderPath = p.Meta.FramePath; player = new PlayerModel { Target = Convert.ToInt32(p.Abnormal.Position)//目标帧号 }; try { DirectoryInfo root = new DirectoryInfo(folderPath); FileInfo[] files = root.GetFiles("*.jpg"); files = files.OrderBy(y => y.Name, new FileComparer()).ToArray(); foreach (var item in files) { string name = item.FullName; imagePath.Add(name); } player.Calculate(imagePath.Count, 120); //播放函数 var t = new Task(() => { int nowPic = player.StartNum; int end = player.EndNum; stop = false; while (!stop && nowPic <= end) { token.ThrowIfCancellationRequested(); DispatcherHelper.CheckBeginInvokeOnUI(() => { ImgSource = imagePath[nowPic]; }); nowPic++; Thread.Sleep(player.Speed); } stop = true; }); t.Start(); } catch (PathTooLongException e) { MessageBox.Show("文件路径过长"); log.Warn("文件路径过长", e); } catch (ArgumentException e) { MessageBox.Show("该路径下文件错误"); log.Warn("该路径下文件错误", e); } catch (Exception e) { MessageBox.Show("发生异常:" + e.ToString()); log.Warn("发生异常", e); } }