星火微课系统客户端
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

ScreenRecordingToolbarWindow.xaml.cs 44KB

4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
4年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176
  1. using Common.system;
  2. using System;
  3. using System.IO;
  4. using System.Threading;
  5. using System.Windows;
  6. using System.Windows.Forms;
  7. using System.Windows.Ink;
  8. using System.Windows.Media;
  9. using System.Windows.Media.Imaging;
  10. using System.Windows.Threading;
  11. using XHWK.Model;
  12. namespace XHWK.WKTool
  13. {
  14. /// <summary>
  15. /// 录屏工具栏
  16. /// </summary>
  17. public partial class ScreenRecordingToolbarWindow : Window
  18. {
  19. #region 初始变量
  20. /// <summary>
  21. /// 视频保存名称
  22. /// </summary>
  23. private string VideoSavePathName;
  24. /// <summary>
  25. /// 是否首次录屏
  26. /// </summary>
  27. private bool IsFirstRS = true;
  28. /// <summary>
  29. /// 是否暂停
  30. /// </summary>
  31. private bool IsSuspend = true;
  32. /// <summary>
  33. /// 视频信息
  34. /// </summary>
  35. private Model_Video VideoInfo = null;
  36. //声明一个 DrawingAttributes 类型的变量
  37. private DrawingAttributes drawingAttributes;
  38. private DispatcherTimer t = null;
  39. /// <summary>
  40. /// 计时器状态
  41. /// </summary>
  42. private enum State
  43. {
  44. Start,
  45. Pause,
  46. End
  47. }
  48. /// <summary>
  49. /// 状态
  50. /// </summary>
  51. private State _state = State.End;
  52. /// <summary>
  53. /// 计时用
  54. /// </summary>
  55. private TimeSpan _timeSpan = new TimeSpan(0, 0, 0, 0, 0);
  56. private KeyboardHookCommon k_hook;
  57. /// <summary>
  58. /// 🖊状态 0红色 1蓝色 10红色批注内 11蓝色批注内
  59. /// </summary>
  60. public int flg = 0;
  61. private System.Timers.Timer timer = new System.Timers.Timer();
  62. #endregion
  63. #region 初始化
  64. /// <summary>
  65. /// 录屏工具栏
  66. /// </summary>
  67. public ScreenRecordingToolbarWindow()
  68. {
  69. InitializeComponent();
  70. this.ResizeMode = ResizeMode.NoResize;
  71. }
  72. /// <summary>
  73. /// 初始化
  74. /// </summary>
  75. public void Initialize()
  76. {
  77. if (APP.W_PracticeWindow == null)
  78. {
  79. APP.W_PracticeWindow = new PracticeWindow
  80. {
  81. //APP.W_PracticeWindow.Topmost = true;
  82. Width = pwidth,
  83. Height = pHeight,
  84. Left = 0,
  85. Top = 0
  86. };
  87. //practiceWin.Owner = this;
  88. }
  89. APP.W_PracticeWindow.Show();
  90. new Thread(new ThreadStart(new Action(() =>
  91. {
  92. Thread.Sleep(100);
  93. Dispatcher.Invoke(() =>
  94. {
  95. this.Owner = APP.W_PracticeWindow;
  96. this.Topmost = true;
  97. });
  98. }))).Start();
  99. APP.W_PracticeWindow.Hide();
  100. //timer = new System.Timers.Timer(200);
  101. //timer.Interval = 300;
  102. //timer.Elapsed += new System.Timers.ElapsedEventHandler(TimerDealy);
  103. //timer.Enabled = true; //启动计时器
  104. borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
  105. borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  106. flg = 0;
  107. k_hook = new KeyboardHookCommon();
  108. k_hook.KeyDownEvent += K_hook_KeyDownEvent;
  109. //创建 DrawingAttributes 类的一个实例
  110. drawingAttributes = new DrawingAttributes();
  111. //将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用
  112. //InkCanvas 通过 DefaultDrawingAttributes 属性来获取墨迹的各种设置,该属性的类型为 DrawingAttributes 型
  113. blackboard_canvas.DefaultDrawingAttributes = drawingAttributes;
  114. drawingAttributes.FitToCurve = true;
  115. //隐藏画笔工具栏
  116. //BtnToolbarDown_Click(null, null);
  117. gridToolbar.Visibility = Visibility.Hidden;
  118. gridColour.Visibility = Visibility.Hidden;
  119. gridThickness.Visibility = Visibility.Hidden;
  120. ImgRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar26.png"));//大圆圈三角形
  121. ImgEndRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar15.png"));
  122. BtnStopRecordingScreen.IsEnabled = false; //停止录制按钮不点击
  123. imgBlackPenOne.Source = new BitmapImage(new Uri("pack://application:,,,/Images/31.png"));
  124. btnBlackPenOne.IsEnabled = false;//蓝笔不可点击
  125. imgBlackPenTwo.Source = new BitmapImage(new Uri("pack://application:,,,/Images/31.png"));
  126. btnBlackPenTwo.IsEnabled = false;//红笔不可点击
  127. //imgReturn.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar29.png"));
  128. //btnReturn.IsEnabled = true;//返回主界面可点击
  129. txbTime.Visibility = Visibility.Hidden;//时间不显示
  130. BtnRecordingScreen.ToolTip = "开始";
  131. if (t == null)
  132. {
  133. t = new DispatcherTimer();
  134. t.Tick += OnTimer;
  135. t.Interval = new TimeSpan(0, 0, 0, 1);
  136. t.IsEnabled = true;
  137. t.Start();
  138. }
  139. t.Interval = new TimeSpan(0, 0, 0, 1);
  140. //Stack();
  141. //ImgRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar25.png"));
  142. //BtnRecordingScreen_Click(null, null);
  143. }
  144. private void TimerDealy(object o, EventArgs e)
  145. {
  146. Dispatcher.Invoke(() =>
  147. {
  148. if (Left > 1630)
  149. {
  150. return;
  151. }
  152. //获取鼠标在屏幕上的位置
  153. double mouse_x = Form.MousePosition.X; //需要添加引用System.Drawing
  154. double mouse_y = Form.MousePosition.Y;
  155. bool is_in_collasped_range = (mouse_y > Left + Height) || (mouse_x < Left || mouse_x > Left + Width);//缩起的条件
  156. bool is_in_visiable_range = (mouse_y < 1 && mouse_x >= Left && mouse_x <= Left + Width); //展开的条件
  157. if (Left < 1630 && Left >= 0 && is_in_collasped_range)
  158. {
  159. System.Threading.Thread.Sleep(300);
  160. Left += 20 /*-this.ActualWidth - 3*/;
  161. }
  162. else if (Left < 0 && is_in_visiable_range)
  163. {
  164. Left = 1;
  165. }
  166. });
  167. }
  168. private void K_hook_KeyDownEvent(object sender, System.Windows.Forms.KeyEventArgs e)
  169. {
  170. if (e.KeyValue == (int)System.Windows.Forms.Keys.F5 && (int)Control.ModifierKeys == (int)Keys.Control)
  171. {
  172. //开始,暂停
  173. BtnRecordingScreen_Click(null, null);
  174. }
  175. if (e.KeyValue == (int)Keys.S && (int)Control.ModifierKeys == (int)Keys.Control)
  176. {
  177. //结束
  178. BtnStopRecordingScreen_Click(null, null);
  179. }
  180. }
  181. #endregion
  182. #region 事件
  183. /// <summary>
  184. /// 时钟回调
  185. /// </summary>
  186. /// <param name="sender"></param>
  187. /// <param name="e"></param>
  188. private void OnTimer(object sender, EventArgs e)
  189. {
  190. switch (_state)
  191. {
  192. case State.Start:
  193. {
  194. _timeSpan += new TimeSpan(0, 0, 0, 1);
  195. }
  196. break;
  197. case State.Pause:
  198. {
  199. }
  200. break;
  201. case State.End:
  202. {
  203. _timeSpan = new TimeSpan();
  204. //_timeSpan = new TimeSpan(0, 23, 12, 45, 54);
  205. }
  206. break;
  207. }
  208. string time = string.Format("{0:D2}:{1:D2}",/* _timeSpan.Hours,*/ _timeSpan.Minutes, _timeSpan.Seconds);
  209. //char[] times = time.ToCharArray();
  210. txbTime.Text = time;
  211. }
  212. /// <summary>
  213. /// 开始
  214. /// </summary>
  215. /// <param name="sender"></param>
  216. /// <param name="e"></param>
  217. private void Stack()
  218. {
  219. _state = State.Start;
  220. }
  221. /// <summary>
  222. /// 暂停
  223. /// </summary>
  224. private void TimeOut()
  225. {
  226. _state = State.Pause;
  227. }
  228. /// <summary>
  229. /// 结束
  230. /// </summary>
  231. /// <param name="sender"></param>
  232. /// <param name="e"></param>
  233. private void End()
  234. {
  235. _state = State.End;
  236. }
  237. #region 录屏
  238. /// <summary>
  239. /// 设置录屏文件地址
  240. /// </summary>
  241. private void SetUpVideoPathName()
  242. {
  243. //FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temp/");
  244. FileToolsCommon.CreateDirectory(APP.WKData.WkPath);
  245. FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temprs/");
  246. VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录屏." + ((Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType"))).ToString();
  247. int num = 1;
  248. while (FileToolsCommon.IsExistFile(VideoSavePathName))
  249. {
  250. VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录屏_" + num + "." + ((Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType"))).ToString();
  251. num++;
  252. }
  253. }
  254. /// <summary>
  255. /// 是否已经按下按钮
  256. /// </summary>
  257. bool IsPressButton = false;
  258. /// <summary>
  259. /// 开始或暂停录制
  260. /// </summary>
  261. /// <param name="sender"></param>
  262. /// <param name="e"></param>
  263. private void BtnRecordingScreen_Click(object sender, RoutedEventArgs e)
  264. {
  265. #region 防止连击
  266. if (IsPressButton)
  267. {
  268. return;
  269. }
  270. else
  271. {
  272. IsPressButton = true;
  273. new Thread(new ThreadStart(new Action(() =>
  274. {
  275. Thread.Sleep(500);
  276. IsPressButton = false;
  277. }))).Start();
  278. }
  279. #endregion
  280. if (IsSuspend)
  281. {
  282. if (IsFirstRS)
  283. {
  284. #region 检测麦克风扬声器是否可用
  285. string audioSpeakerPath = FileToolsCommon.GetFileAbsolutePath("adoS.m");
  286. string audioMicrophonePath = FileToolsCommon.GetFileAbsolutePath("adoM.m");
  287. try
  288. {
  289. FileToolsCommon.DeleteFile(audioSpeakerPath);
  290. FileToolsCommon.DeleteFile(audioMicrophonePath);
  291. }
  292. catch (Exception)
  293. {
  294. }
  295. //扬声器
  296. if (APP.FFmpeg.StartRecordSpeakerAudio(audioSpeakerPath))
  297. {
  298. APP.FFmpeg.StopRecordAudio(2);
  299. //Thread.Sleep(500);
  300. //麦克风
  301. if (APP.FFmpeg.StartRecordAudio(audioMicrophonePath))
  302. {
  303. }
  304. else
  305. {
  306. //无法录制麦克风
  307. MessageBoxResult Res = MessageWindow.Show("当前电脑无法录制麦克风,是否继续?", "消息提示", MessageBoxButton.OKCancel);
  308. if (Res == MessageBoxResult.Cancel)
  309. {
  310. return;
  311. }
  312. }
  313. APP.FFmpeg.StopRecordAudio(1);
  314. }
  315. else
  316. {
  317. //无法录制扬声器音频
  318. MessageBoxResult Res = MessageWindow.Show("当前电脑无法录制音频,是否继续?", "消息提示", MessageBoxButton.OKCancel);
  319. if (Res == MessageBoxResult.Cancel)
  320. {
  321. return;
  322. }
  323. }
  324. #endregion
  325. VideoInfo = new Model_Video
  326. {
  327. VideoType = (Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType")),
  328. WkType = Enum_WKVidetype.RecordingScreen
  329. };
  330. SetUpVideoPathName();
  331. k_hook.Start();//安装键盘钩子
  332. if (APP.W_CountdownWindow == null)
  333. {
  334. APP.W_CountdownWindow = new CountdownWindow();
  335. APP.W_CountdownWindow.Initialize(true, 1800);
  336. //APP.W_CountdownWindow.Topmost = true;
  337. }
  338. else
  339. {
  340. APP.W_CountdownWindow.Initialize(true, 1800);
  341. //APP.W_CountdownWindow.Topmost = true;
  342. }
  343. APP.W_CountdownWindow.Show();
  344. }
  345. IsSuspend = false;
  346. //#region 录像倒计时
  347. //if (APP.W_CountdownWindow == null)
  348. //{
  349. // APP.W_CountdownWindow = new CountdownWindow();
  350. // //APP.W_CountdownWindow.Topmost = true;
  351. //}
  352. //else
  353. //{
  354. // APP.W_CountdownWindow.Initialize();
  355. // //APP.W_CountdownWindow.Topmost = true;
  356. //}
  357. //APP.W_CountdownWindow.Show();
  358. //#endregion
  359. ImgRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar25.png"));//播放状态
  360. ImgEndRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar14.png"));
  361. BtnStopRecordingScreen.IsEnabled = true; //停止录制按钮可点击
  362. imgBlackPenOne.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar27.png"));
  363. btnBlackPenOne.IsEnabled = true;//蓝笔可点击
  364. imgBlackPenTwo.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar28.png"));
  365. btnBlackPenTwo.IsEnabled = true;//红笔可点击
  366. txbTime.Visibility = Visibility.Visible;//时间显示
  367. //imgReturn.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar30.png"));
  368. //borOne.Background = new SolidColorBrush(Colors.LightBlue);
  369. BtnRecordingScreen.ToolTip = "暂停";
  370. try
  371. {
  372. #region 4秒内不可点击
  373. new Thread(new ThreadStart(new Action(() =>
  374. {
  375. //Dispatcher.Invoke(() =>
  376. //{
  377. // ImgEndRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar15.png"));
  378. // BtnRecordingScreen.IsEnabled = false;
  379. // BtnStopRecordingScreen.IsEnabled = false;
  380. //});
  381. //Thread.Sleep(4000);
  382. Dispatcher.Invoke(() =>
  383. {
  384. ImgEndRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar14.png"));
  385. BtnRecordingScreen.IsEnabled = true;
  386. BtnStopRecordingScreen.IsEnabled = true;
  387. });
  388. }))).Start();
  389. #endregion
  390. new Thread(new ThreadStart(new Action(() =>
  391. {
  392. if (IsFirstRS)
  393. {
  394. Thread.Sleep(800);
  395. }
  396. if(APP.FFmpeg.myProcess!=null)
  397. {
  398. Thread.Sleep(100);
  399. }
  400. APP.FFmpeg.StartRecordingVideo(VideoSavePathName);
  401. Thread.Sleep(1300);
  402. Dispatcher.Invoke(() =>
  403. {
  404. Stack();
  405. });
  406. }))).Start();
  407. }
  408. catch (Exception ex)
  409. {
  410. MessageWindow.Show(ex.Message);
  411. }
  412. IsFirstRS = false;
  413. }
  414. else
  415. {
  416. TimeOut();
  417. IsSuspend = true;
  418. ImgRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar26.png"));//大圆圈三角形
  419. BtnStopRecordingScreen.IsEnabled = false; //停止录制按钮不点击
  420. BtnRecordingScreen.ToolTip = "开始";
  421. //imgBlackPenOne.Source = new BitmapImage(new Uri("pack://application:,,,/Images/31.png"));
  422. //btnBlackPenOne.IsEnabled = false;//蓝笔不可点击
  423. //imgBlackPenTwo.Source = new BitmapImage(new Uri("pack://application:,,,/Images/31.png"));
  424. //btnBlackPenTwo.IsEnabled = false;//红笔不可点击
  425. txbTime.Visibility = Visibility.Hidden;//时间不显示
  426. //imgReturn.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar29.png"));
  427. //btnReturn.IsEnabled = true;//返回主界面可点击
  428. #region 2秒内不可点击
  429. new Thread(new ThreadStart(new Action(() =>
  430. {
  431. //Dispatcher.Invoke(() =>
  432. //{
  433. // ImgEndRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar15.png"));
  434. // BtnRecordingScreen.IsEnabled = false;
  435. // BtnStopRecordingScreen.IsEnabled = false;
  436. //});
  437. //Thread.Sleep(2000);
  438. Dispatcher.Invoke(() =>
  439. {
  440. ImgEndRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar14.png"));
  441. BtnRecordingScreen.IsEnabled = true;
  442. BtnStopRecordingScreen.IsEnabled = true;
  443. });
  444. }))).Start();
  445. #endregion
  446. try
  447. {
  448. APP.FFmpeg.SuspendFFmpeg();
  449. }
  450. catch (Exception ex)
  451. {
  452. MessageWindow.Show(ex.Message);
  453. }
  454. }
  455. }
  456. /// <summary>
  457. /// 停止录像
  458. /// </summary>
  459. /// <param name="sender"></param>
  460. /// <param name="e"></param>
  461. private void BtnStopRecordingScreen_Click(object sender, RoutedEventArgs e)
  462. {
  463. #region 防止连击
  464. if (IsPressButton)
  465. {
  466. return;
  467. }
  468. else
  469. {
  470. IsPressButton = true;
  471. new Thread(new ThreadStart(new Action(() =>
  472. {
  473. Thread.Sleep(500);
  474. IsPressButton = false;
  475. }))).Start();
  476. }
  477. #endregion
  478. k_hook.Stop();
  479. IsSuspend = true;
  480. txbTime.Text = "00:00";
  481. txbTime.Visibility = Visibility.Hidden;
  482. End();
  483. if (APP.W_PracticeWindow != null)
  484. {
  485. if (APP.W_PracticeWindow.Visibility == Visibility.Visible)
  486. {
  487. this.Owner = null;
  488. APP.W_PracticeWindow.ReturnPractice();
  489. }
  490. }
  491. if (gridToolbar.Visibility == Visibility.Visible)
  492. {
  493. gridToolbar.Visibility = Visibility.Hidden;
  494. gridColour.Visibility = Visibility.Hidden;
  495. gridThickness.Visibility = Visibility.Hidden;
  496. }
  497. if (APP.W_XHMicroLessonSystemWindow == null)
  498. {
  499. APP.W_XHMicroLessonSystemWindow = new XHMicroLessonSystemWindow();
  500. }
  501. APP.W_XHMicroLessonSystemWindow.InitializeKeyDownEvent();
  502. APP.W_XHMicroLessonSystemWindow.Show();
  503. if (!IsFirstRS)
  504. {
  505. try
  506. {
  507. if (_timeSpan.Minutes > 0 || _timeSpan.Seconds > 3)
  508. {
  509. try
  510. {
  511. APP.FFmpeg.StopFFmpeg(VideoSavePathName);
  512. }
  513. catch (Exception ex)
  514. {
  515. LogHelper.WriteErrLog("【停止录屏】(BtnStopRecordingScreen_Click)" + ex.Message, ex);
  516. }
  517. IsFirstRS = true;
  518. //生成缩略图
  519. string ThumbnailPath = FileToolsCommon.GetDirectoryName(VideoSavePathName) + "ThumbnailPath/";
  520. FileToolsCommon.CreateDirectory(ThumbnailPath);
  521. //缩略图存储位置
  522. string ThumbnailPathName = ThumbnailPath + FileToolsCommon.GetIOFileName(VideoSavePathName).Replace(".", "") + ".JPG";
  523. new Thread(new ThreadStart(new Action(() =>
  524. {
  525. while (!FileToolsCommon.IsExistFile(VideoSavePathName))
  526. {
  527. Thread.Sleep(100);
  528. }
  529. FileToolsCommon.DeleteFile(ThumbnailPathName);
  530. //VideoInfo.VideoSize = FileToolsCommon.GetFileSizeByMB(VideoSavePathName).ToString() + " MB";
  531. VideoInfo.RSTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  532. VideoInfo.VideoPath = VideoSavePathName;
  533. VideoInfo.ThumbnailPath = ThumbnailPathName;
  534. APP.FFmpeg.GenerateThumbnails(VideoSavePathName, ThumbnailPathName, 200, 130);
  535. VideoInfo.FileGuid = Guid.NewGuid().ToString();
  536. VideoInfo.IsUpload = false;
  537. VideoInfo.Uploaded = 0;
  538. VideoInfo.Savefolder = APP.UserInfo.Schoolid + "/resource";
  539. APP.VideoList.Add(VideoInfo);
  540. //保存数据
  541. APP.SaveWkData();
  542. }))).Start();
  543. Click_stopRecordingScreen();
  544. }
  545. else
  546. {
  547. //视频过短
  548. APP.FFmpeg.SuspendFFmpeg();
  549. IsFirstRS = true;
  550. MessageWindow.Show("保存失败,录屏时间过短!");
  551. }
  552. }
  553. catch (Exception ex)
  554. {
  555. LogHelper.WriteErrLog("【停止录屏】(BtnStopRecordingScreen_Click)" + ex.Message, ex);
  556. }
  557. }
  558. Hide();
  559. }
  560. #endregion
  561. #region 画笔相关
  562. /// <summary>
  563. /// 画笔工具栏关闭事件
  564. /// </summary>
  565. /// <param name="sender"></param>
  566. /// <param name="e"></param>
  567. private void BtnToolbarDown_Click(object sender, RoutedEventArgs e)
  568. {
  569. gridToolbar.Visibility = Visibility.Hidden;
  570. gridColour.Visibility = Visibility.Hidden;
  571. gridThickness.Visibility = Visibility.Hidden;
  572. APP.W_PracticeWindow.Hide();
  573. }
  574. /// <summary>
  575. /// 画笔点击事件
  576. /// </summary>
  577. /// <param name="sender"></param>
  578. /// <param name="e"></param>
  579. private void BtnBrush_Click(object sender, RoutedEventArgs e)
  580. {
  581. #region 防止连击
  582. if (IsPressButton)
  583. {
  584. return;
  585. }
  586. else
  587. {
  588. IsPressButton = true;
  589. new Thread(new ThreadStart(new Action(() =>
  590. {
  591. Thread.Sleep(500);
  592. IsPressButton = false;
  593. }))).Start();
  594. }
  595. #endregion
  596. string time = GetTimeStamp();
  597. string tempPath = AppDomain.CurrentDomain.BaseDirectory + "temp\\";
  598. if (!Directory.Exists(tempPath))
  599. {
  600. Directory.CreateDirectory(tempPath);
  601. }
  602. #region 录屏批注取消画笔
  603. //string imagePath = Path.Combine(tempPath, time + ".jpg");
  604. //ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), imagePath, true, out BitmapImage bitmap);
  605. #endregion
  606. try
  607. {
  608. if (flg == 11)
  609. {
  610. Dispatcher.Invoke(() =>
  611. {
  612. borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
  613. borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  614. });
  615. flg = 1;
  616. //this.Owner = null;
  617. APP.W_PracticeWindow.ReturnPractice();
  618. }
  619. else if (flg == 10)
  620. {
  621. Dispatcher.Invoke(() =>
  622. {
  623. borOne.Background = new SolidColorBrush(Colors.LightSkyBlue);
  624. borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  625. });
  626. APP.W_PracticeWindow.Blue();
  627. flg = 11;
  628. }
  629. else
  630. {
  631. //new Thread(new ThreadStart(new Action(() =>
  632. //{
  633. Dispatcher.Invoke(() =>
  634. {
  635. borOne.Background = new SolidColorBrush(Colors.LightSkyBlue);
  636. borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  637. });
  638. //}))).Start();
  639. if (APP.W_PracticeWindow == null)
  640. {
  641. APP.W_PracticeWindow = new PracticeWindow
  642. {
  643. //APP.W_PracticeWindow.Topmost = true;
  644. Width = pwidth,
  645. Height = pHeight,
  646. Left = 0,
  647. Top = 0
  648. };
  649. //practiceWin.Owner = this;
  650. }
  651. APP.W_PracticeWindow.Initialize();// imagePath);
  652. flg = 11;
  653. APP.W_PracticeWindow.Blue();
  654. APP.W_PracticeWindow.Show();
  655. new Thread(new ThreadStart(new Action(() =>
  656. {
  657. Thread.Sleep(100);
  658. Dispatcher.Invoke(() =>
  659. {
  660. this.Owner = APP.W_PracticeWindow;
  661. this.Topmost = true;
  662. });
  663. }))).Start();
  664. }
  665. }
  666. catch (Exception ex)
  667. {
  668. LogHelper.WriteErrLog("【批注(PracticeWindow)" + ex.Message, ex);
  669. }
  670. //imgCanvas.Source = new BitmapImage(new Uri(imagePath));
  671. }
  672. /// <summary>
  673. /// 屏幕宽
  674. /// </summary>
  675. internal double pwidth = SystemParameters.PrimaryScreenWidth;
  676. /// <summary>
  677. /// 屏幕高
  678. /// </summary>
  679. internal double pHeight = SystemParameters.PrimaryScreenHeight;
  680. /// <summary>
  681. /// 获取时间戳
  682. /// </summary>
  683. /// <returns></returns>
  684. public string GetTimeStamp()
  685. {
  686. TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  687. return Convert.ToInt64(ts.TotalMilliseconds).ToString();
  688. }
  689. /// <summary>
  690. /// 画笔粗细事件
  691. /// </summary>
  692. /// <param name="sender"></param>
  693. /// <param name="e"></param>
  694. private void BtnThickness_Click(object sender, RoutedEventArgs e)
  695. {
  696. gridThickness.Visibility = Visibility.Visible;
  697. gridColour.Visibility = Visibility.Collapsed;
  698. }
  699. /// <summary>
  700. /// 画笔颜色事件
  701. /// </summary>
  702. /// <param name="sender"></param>
  703. /// <param name="e"></param>
  704. private void BtnColour_Click(object sender, RoutedEventArgs e)
  705. {
  706. gridColour.Visibility = Visibility.Visible;
  707. gridThickness.Visibility = Visibility.Collapsed;
  708. }
  709. /// <summary>
  710. /// 白色
  711. /// </summary>
  712. /// <param name="sender"></param>
  713. /// <param name="e"></param>
  714. private void BtnWhite_Click(object sender, RoutedEventArgs e)
  715. {
  716. //drawingAttributes.Color = Colors.White;
  717. APP.W_PracticeWindow.White();
  718. gridColour.Visibility = Visibility.Collapsed;
  719. gridThickness.Visibility = Visibility.Collapsed;
  720. }
  721. /// <summary>
  722. /// 红色
  723. /// </summary>
  724. /// <param name="sender"></param>
  725. /// <param name="e"></param>
  726. private void BtnRed_Click(object sender, RoutedEventArgs e)
  727. {
  728. //drawingAttributes.Color = Colors.Red;
  729. APP.W_PracticeWindow.Red();
  730. gridColour.Visibility = Visibility.Collapsed;
  731. gridThickness.Visibility = Visibility.Collapsed;
  732. }
  733. /// <summary>
  734. /// 黄色
  735. /// </summary>
  736. /// <param name="sender"></param>
  737. /// <param name="e"></param>
  738. private void BtnYellow_Click(object sender, RoutedEventArgs e)
  739. {
  740. //drawingAttributes.Color = Colors.Gold;
  741. APP.W_PracticeWindow.Yellow();
  742. gridColour.Visibility = Visibility.Collapsed;
  743. gridThickness.Visibility = Visibility.Collapsed;
  744. }
  745. /// <summary>
  746. /// 青色
  747. /// </summary>
  748. /// <param name="sender"></param>
  749. /// <param name="e"></param>
  750. private void BtnCyanBlue_Click(object sender, RoutedEventArgs e)
  751. {
  752. //drawingAttributes.Color = Colors.LimeGreen;
  753. APP.W_PracticeWindow.CyanBlue();
  754. gridColour.Visibility = Visibility.Collapsed;
  755. gridThickness.Visibility = Visibility.Collapsed;
  756. }
  757. /// <summary>
  758. /// 灰色
  759. /// </summary>
  760. /// <param name="sender"></param>
  761. /// <param name="e"></param>
  762. private void BtnGray_Click(object sender, RoutedEventArgs e)
  763. {
  764. //drawingAttributes.Color = Colors.Gray;
  765. APP.W_PracticeWindow.Gray();
  766. gridColour.Visibility = Visibility.Collapsed;
  767. gridThickness.Visibility = Visibility.Collapsed;
  768. }
  769. /// <summary>
  770. /// 蓝色
  771. /// </summary>
  772. /// <param name="sender"></param>
  773. /// <param name="e"></param>
  774. private void BtnBlue_Click(object sender, RoutedEventArgs e)
  775. {
  776. //drawingAttributes.Color = Colors.DeepSkyBlue;
  777. APP.W_PracticeWindow.Blue();
  778. gridColour.Visibility = Visibility.Collapsed;
  779. gridThickness.Visibility = Visibility.Collapsed;
  780. }
  781. /// <summary>
  782. /// 画笔 细
  783. /// </summary>
  784. /// <param name="sender"></param>
  785. /// <param name="e"></param>
  786. private void BtnFine_Click(object sender, RoutedEventArgs e)
  787. {
  788. APP.W_PracticeWindow.Fine();
  789. gridColour.Visibility = Visibility.Collapsed;
  790. gridThickness.Visibility = Visibility.Collapsed;
  791. }
  792. /// <summary>
  793. /// 画笔 中
  794. /// </summary>
  795. /// <param name="sender"></param>
  796. /// <param name="e"></param>
  797. private void BtnIn_Click(object sender, RoutedEventArgs e)
  798. {
  799. APP.W_PracticeWindow.In();
  800. gridColour.Visibility = Visibility.Collapsed;
  801. gridThickness.Visibility = Visibility.Collapsed;
  802. }
  803. /// <summary>
  804. /// 画笔粗
  805. /// </summary>
  806. /// <param name="sender"></param>
  807. /// <param name="e"></param>
  808. private void BtnCrude_Click(object sender, RoutedEventArgs e)
  809. {
  810. APP.W_PracticeWindow.Crude();
  811. gridColour.Visibility = Visibility.Collapsed;
  812. gridThickness.Visibility = Visibility.Collapsed;
  813. }
  814. /// <summary>
  815. /// 橡皮
  816. /// </summary>
  817. /// <param name="sender"></param>
  818. /// <param name="e"></param>
  819. private void BtnEraser_Click(object sender, RoutedEventArgs e)
  820. {
  821. APP.W_PracticeWindow.Eraser();
  822. }
  823. /// <summary>
  824. /// 🖊
  825. /// </summary>
  826. /// <param name="sender"></param>
  827. /// <param name="e"></param>
  828. private void BtnPen_Click(object sender, RoutedEventArgs e)
  829. {
  830. APP.W_PracticeWindow.Pen();
  831. }
  832. /// <summary>
  833. /// ⚪
  834. /// </summary>
  835. /// <param name="sender"></param>
  836. /// <param name="e"></param>
  837. private void BtnRound_Click(object sender, RoutedEventArgs e)
  838. {
  839. APP.W_PracticeWindow.Round();
  840. }
  841. /// <summary>
  842. /// 矩形
  843. /// </summary>
  844. /// <param name="sender"></param>
  845. /// <param name="e"></param>
  846. private void BtnRectangle_Click(object sender, RoutedEventArgs e)
  847. {
  848. APP.W_PracticeWindow.Rectangle();
  849. }
  850. #endregion
  851. #endregion
  852. /// <summary>
  853. /// 停止录屏
  854. /// </summary>
  855. public delegate void StopRecordingScreen();
  856. /// <summary>
  857. /// 停止录屏
  858. /// </summary>
  859. public event StopRecordingScreen Click_stopRecordingScreen;
  860. /// <summary>
  861. /// 黑笔
  862. /// </summary>
  863. /// <param name="sender"></param>
  864. /// <param name="e"></param>
  865. private void BtnBlackPen_Click(object sender, RoutedEventArgs e)
  866. {
  867. }
  868. /// <summary>
  869. /// 移动工具栏
  870. /// </summary>
  871. /// <param name="sender"></param>
  872. /// <param name="e"></param>
  873. private void Grid_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
  874. {
  875. DragMove();
  876. }
  877. /// <summary>
  878. /// 红笔
  879. /// </summary>
  880. /// <param name="sender"></param>
  881. /// <param name="e"></param>
  882. private void BtnBlackPenTwo_Click(object sender, RoutedEventArgs e)
  883. {
  884. #region 防止连击
  885. if (IsPressButton)
  886. {
  887. return;
  888. }
  889. else
  890. {
  891. IsPressButton = true;
  892. new Thread(new ThreadStart(new Action(() =>
  893. {
  894. Thread.Sleep(500);
  895. IsPressButton = false;
  896. }))).Start();
  897. }
  898. #endregion
  899. string time = GetTimeStamp();
  900. string tempPath = AppDomain.CurrentDomain.BaseDirectory + "temp\\";
  901. if (!Directory.Exists(tempPath))
  902. {
  903. Directory.CreateDirectory(tempPath);
  904. }
  905. #region 录屏批注取消画笔
  906. string imagePath = Path.Combine(tempPath, time + ".jpg");
  907. ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), imagePath, true, out BitmapImage bitmap);
  908. #endregion
  909. try
  910. {
  911. if (flg == 10)
  912. {
  913. Dispatcher.Invoke(() =>
  914. {
  915. borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
  916. borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  917. });
  918. flg = 0;
  919. //this.Owner = null;
  920. APP.W_PracticeWindow.ReturnPractice();
  921. }
  922. else if (flg == 11)
  923. {
  924. Dispatcher.Invoke(() =>
  925. {
  926. borTwo.Background = new SolidColorBrush(Colors.LightSkyBlue);
  927. borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
  928. });
  929. flg = 10;
  930. APP.W_PracticeWindow.Red();
  931. }
  932. else
  933. {
  934. Dispatcher.Invoke(() =>
  935. {
  936. borTwo.Background = new SolidColorBrush(Colors.LightSkyBlue);
  937. borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
  938. });
  939. if (APP.W_PracticeWindow == null)
  940. {
  941. APP.W_PracticeWindow = new PracticeWindow
  942. {
  943. //APP.W_PracticeWindow.Topmost = true;
  944. Width = pwidth,
  945. Height = pHeight,
  946. Left = 0,
  947. Top = 0
  948. };
  949. //practiceWin.Owner = this;
  950. }
  951. APP.W_PracticeWindow.Initialize();//imagePath);
  952. flg = 10;
  953. APP.W_PracticeWindow.Red();
  954. APP.W_PracticeWindow.Show();
  955. new Thread(new ThreadStart(new Action(() =>
  956. {
  957. Thread.Sleep(100);
  958. Dispatcher.Invoke(() =>
  959. {
  960. this.Owner = APP.W_PracticeWindow;
  961. this.Topmost = true;
  962. });
  963. }))).Start();
  964. }
  965. }
  966. catch (Exception ex)
  967. {
  968. LogHelper.WriteErrLog("【批注(PracticeWindow)" + ex.Message, ex);
  969. }
  970. }
  971. /// <summary>
  972. /// 鼠标右键按下事件 废弃
  973. /// </summary>
  974. /// <param name="sender"></param>
  975. /// <param name="e"></param>
  976. private void RightButtonDown()
  977. {
  978. if (flg > 9)
  979. {
  980. this.Owner = null;
  981. APP.W_PracticeWindow.Hide();
  982. }
  983. else
  984. {
  985. //string time = GetTimeStamp();
  986. string tempPath = AppDomain.CurrentDomain.BaseDirectory + "temp\\";
  987. if (!Directory.Exists(tempPath))
  988. {
  989. Directory.CreateDirectory(tempPath);
  990. }
  991. #region 录屏批注取消画笔
  992. //string imagePath = Path.Combine(tempPath, time + ".jpg");
  993. //ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), imagePath, true, out BitmapImage bitmap);
  994. #endregion
  995. try
  996. {
  997. if (APP.W_PracticeWindow == null)
  998. {
  999. APP.W_PracticeWindow = new PracticeWindow
  1000. {
  1001. //APP.W_PracticeWindow.Topmost = true;
  1002. Width = pwidth,
  1003. Height = pHeight,
  1004. Left = 0,
  1005. Top = 0
  1006. };
  1007. //practiceWin.Owner = this;
  1008. }
  1009. APP.W_PracticeWindow.Initialize();//imagePath);
  1010. if (flg == 0)
  1011. {
  1012. flg = 10;
  1013. APP.W_PracticeWindow.Red();
  1014. }
  1015. else
  1016. {
  1017. flg = 11;
  1018. APP.W_PracticeWindow.Blue();
  1019. }
  1020. APP.W_PracticeWindow.Show();
  1021. }
  1022. catch (Exception ex)
  1023. {
  1024. LogHelper.WriteErrLog("【批注(PracticeWindow)" + ex.Message, ex);
  1025. }
  1026. }
  1027. }
  1028. /// <summary>
  1029. /// 返回主界面
  1030. /// </summary>
  1031. /// <param name="sender"></param>
  1032. /// <param name="e"></param>
  1033. private void BtnReturn_Click(object sender, RoutedEventArgs e)
  1034. {
  1035. if (!IsFirstRS)
  1036. {
  1037. MessageBoxResult br = MessageWindow.Show("退出将不保存当前录屏!", "提示", MessageBoxButton.OKCancel);
  1038. if (br == MessageBoxResult.Cancel)
  1039. {
  1040. return;
  1041. }
  1042. k_hook.Stop();
  1043. IsSuspend = true;
  1044. txbTime.Text = "00:00";
  1045. txbTime.Visibility = Visibility.Hidden;
  1046. End();
  1047. APP.W_PracticeWindow.ReturnPractice();
  1048. if (APP.W_PracticeWindow != null)
  1049. {
  1050. if (APP.W_PracticeWindow.Visibility == Visibility.Visible)
  1051. {
  1052. APP.W_PracticeWindow.Hide();
  1053. }
  1054. }
  1055. if (gridToolbar.Visibility == Visibility.Visible)
  1056. {
  1057. gridToolbar.Visibility = Visibility.Hidden;
  1058. gridColour.Visibility = Visibility.Hidden;
  1059. gridThickness.Visibility = Visibility.Hidden;
  1060. }
  1061. if (APP.W_XHMicroLessonSystemWindow == null)
  1062. {
  1063. APP.W_XHMicroLessonSystemWindow = new XHMicroLessonSystemWindow();
  1064. }
  1065. try
  1066. {
  1067. try
  1068. {
  1069. APP.FFmpeg.SuspendFFmpeg();
  1070. }
  1071. catch (Exception ex)
  1072. {
  1073. LogHelper.WriteErrLog("【录屏返回】(BtnStopRecordingScreen_Click)" + ex.Message, ex);
  1074. }
  1075. IsFirstRS = true;
  1076. new Thread(new ThreadStart(new Action(() =>
  1077. {
  1078. VideoInfo = null;
  1079. FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temprs/");
  1080. }))).Start();
  1081. }
  1082. catch (Exception ex)
  1083. {
  1084. LogHelper.WriteErrLog("【录屏返回】(BtnStopRecordingScreen_Click)" + ex.Message, ex);
  1085. }
  1086. }
  1087. APP.W_XHMicroLessonSystemWindow.InitializeKeyDownEvent();
  1088. APP.W_XHMicroLessonSystemWindow.Show();
  1089. Hide();
  1090. }
  1091. /// <summary>
  1092. /// 批注退出 废弃
  1093. /// </summary>
  1094. public void ReturnPractice()
  1095. {
  1096. new Thread(new ThreadStart(new Action(() =>
  1097. {
  1098. Dispatcher.Invoke(() =>
  1099. {
  1100. borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
  1101. borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  1102. });
  1103. flg = 0;
  1104. Thread.Sleep(500);
  1105. Dispatcher.Invoke(() =>
  1106. {
  1107. this.Owner = null;
  1108. APP.W_PracticeWindow.Hide();
  1109. });
  1110. }))).Start();
  1111. //Dispatcher.Invoke(() =>
  1112. //{
  1113. // borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
  1114. // borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  1115. //});
  1116. //flg = 0;
  1117. //Thread.Sleep(300);
  1118. //APP.W_PracticeWindow.Hide();
  1119. }
  1120. /// <summary>
  1121. /// 修改笔状态
  1122. /// </summary>
  1123. public void ModifyState()
  1124. {
  1125. borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
  1126. borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  1127. }
  1128. }
  1129. }