星火微课系统客户端
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

ScreenRecordingToolbarWindow.xaml.cs 44KB

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