星火微课系统客户端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ScreenRecordingToolbarWindow.xaml.cs 44KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170
  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. Thread.Sleep(800);
  393. if(APP.FFmpeg.myProcess!=null)
  394. {
  395. Thread.Sleep(100);
  396. }
  397. APP.FFmpeg.StartRecordingVideo(VideoSavePathName);
  398. Thread.Sleep(1300);
  399. Dispatcher.Invoke(() =>
  400. {
  401. Stack();
  402. });
  403. }))).Start();
  404. }
  405. catch (Exception ex)
  406. {
  407. MessageWindow.Show(ex.Message);
  408. }
  409. }
  410. else
  411. {
  412. TimeOut();
  413. IsSuspend = true;
  414. ImgRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar26.png"));//大圆圈三角形
  415. BtnStopRecordingScreen.IsEnabled = false; //停止录制按钮不点击
  416. BtnRecordingScreen.ToolTip = "开始";
  417. //imgBlackPenOne.Source = new BitmapImage(new Uri("pack://application:,,,/Images/31.png"));
  418. //btnBlackPenOne.IsEnabled = false;//蓝笔不可点击
  419. //imgBlackPenTwo.Source = new BitmapImage(new Uri("pack://application:,,,/Images/31.png"));
  420. //btnBlackPenTwo.IsEnabled = false;//红笔不可点击
  421. txbTime.Visibility = Visibility.Hidden;//时间不显示
  422. //imgReturn.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar29.png"));
  423. //btnReturn.IsEnabled = true;//返回主界面可点击
  424. #region 2秒内不可点击
  425. new Thread(new ThreadStart(new Action(() =>
  426. {
  427. //Dispatcher.Invoke(() =>
  428. //{
  429. // ImgEndRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar15.png"));
  430. // BtnRecordingScreen.IsEnabled = false;
  431. // BtnStopRecordingScreen.IsEnabled = false;
  432. //});
  433. //Thread.Sleep(2000);
  434. Dispatcher.Invoke(() =>
  435. {
  436. ImgEndRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar14.png"));
  437. BtnRecordingScreen.IsEnabled = true;
  438. BtnStopRecordingScreen.IsEnabled = true;
  439. });
  440. }))).Start();
  441. #endregion
  442. try
  443. {
  444. APP.FFmpeg.SuspendFFmpeg();
  445. }
  446. catch (Exception ex)
  447. {
  448. MessageWindow.Show(ex.Message);
  449. }
  450. }
  451. }
  452. /// <summary>
  453. /// 停止录像
  454. /// </summary>
  455. /// <param name="sender"></param>
  456. /// <param name="e"></param>
  457. private void BtnStopRecordingScreen_Click(object sender, RoutedEventArgs e)
  458. {
  459. #region 防止连击
  460. if (IsPressButton)
  461. {
  462. return;
  463. }
  464. else
  465. {
  466. IsPressButton = true;
  467. new Thread(new ThreadStart(new Action(() =>
  468. {
  469. Thread.Sleep(500);
  470. IsPressButton = false;
  471. }))).Start();
  472. }
  473. #endregion
  474. k_hook.Stop();
  475. IsSuspend = true;
  476. txbTime.Text = "00:00";
  477. txbTime.Visibility = Visibility.Hidden;
  478. End();
  479. if (APP.W_PracticeWindow != null)
  480. {
  481. if (APP.W_PracticeWindow.Visibility == Visibility.Visible)
  482. {
  483. this.Owner = null;
  484. APP.W_PracticeWindow.Hide();
  485. }
  486. }
  487. if (gridToolbar.Visibility == Visibility.Visible)
  488. {
  489. gridToolbar.Visibility = Visibility.Hidden;
  490. gridColour.Visibility = Visibility.Hidden;
  491. gridThickness.Visibility = Visibility.Hidden;
  492. }
  493. if (APP.W_XHMicroLessonSystemWindow == null)
  494. {
  495. APP.W_XHMicroLessonSystemWindow = new XHMicroLessonSystemWindow();
  496. }
  497. APP.W_XHMicroLessonSystemWindow.InitializeKeyDownEvent();
  498. APP.W_XHMicroLessonSystemWindow.Show();
  499. if (!IsFirstRS)
  500. {
  501. try
  502. {
  503. if (_timeSpan.Minutes > 0 || _timeSpan.Seconds > 3)
  504. {
  505. try
  506. {
  507. APP.FFmpeg.StopFFmpeg(VideoSavePathName);
  508. }
  509. catch (Exception ex)
  510. {
  511. LogHelper.WriteErrLog("【停止录屏】(BtnStopRecordingScreen_Click)" + ex.Message, ex);
  512. }
  513. IsFirstRS = true;
  514. //生成缩略图
  515. string ThumbnailPath = FileToolsCommon.GetDirectoryName(VideoSavePathName) + "ThumbnailPath/";
  516. FileToolsCommon.CreateDirectory(ThumbnailPath);
  517. //缩略图存储位置
  518. string ThumbnailPathName = ThumbnailPath + FileToolsCommon.GetIOFileName(VideoSavePathName).Replace(".", "") + ".JPG";
  519. new Thread(new ThreadStart(new Action(() =>
  520. {
  521. while (!FileToolsCommon.IsExistFile(VideoSavePathName))
  522. {
  523. Thread.Sleep(100);
  524. }
  525. FileToolsCommon.DeleteFile(ThumbnailPathName);
  526. //VideoInfo.VideoSize = FileToolsCommon.GetFileSizeByMB(VideoSavePathName).ToString() + " MB";
  527. VideoInfo.RSTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  528. VideoInfo.VideoPath = VideoSavePathName;
  529. VideoInfo.ThumbnailPath = ThumbnailPathName;
  530. APP.FFmpeg.GenerateThumbnails(VideoSavePathName, ThumbnailPathName, 200, 130);
  531. VideoInfo.FileGuid = Guid.NewGuid().ToString();
  532. VideoInfo.IsUpload = false;
  533. VideoInfo.Uploaded = 0;
  534. VideoInfo.Savefolder = APP.UserInfo.Schoolid + "/resource";
  535. APP.VideoList.Add(VideoInfo);
  536. //保存数据
  537. APP.SaveWkData();
  538. }))).Start();
  539. Click_stopRecordingScreen();
  540. }
  541. else
  542. {
  543. //视频过短
  544. APP.FFmpeg.SuspendFFmpeg();
  545. IsFirstRS = true;
  546. MessageWindow.Show("保存失败,录屏时间过短!");
  547. }
  548. }
  549. catch (Exception ex)
  550. {
  551. LogHelper.WriteErrLog("【停止录屏】(BtnStopRecordingScreen_Click)" + ex.Message, ex);
  552. }
  553. }
  554. Hide();
  555. }
  556. #endregion
  557. #region 画笔相关
  558. /// <summary>
  559. /// 画笔工具栏关闭事件
  560. /// </summary>
  561. /// <param name="sender"></param>
  562. /// <param name="e"></param>
  563. private void BtnToolbarDown_Click(object sender, RoutedEventArgs e)
  564. {
  565. gridToolbar.Visibility = Visibility.Hidden;
  566. gridColour.Visibility = Visibility.Hidden;
  567. gridThickness.Visibility = Visibility.Hidden;
  568. APP.W_PracticeWindow.Hide();
  569. }
  570. /// <summary>
  571. /// 画笔点击事件
  572. /// </summary>
  573. /// <param name="sender"></param>
  574. /// <param name="e"></param>
  575. private void BtnBrush_Click(object sender, RoutedEventArgs e)
  576. {
  577. #region 防止连击
  578. if (IsPressButton)
  579. {
  580. return;
  581. }
  582. else
  583. {
  584. IsPressButton = true;
  585. new Thread(new ThreadStart(new Action(() =>
  586. {
  587. Thread.Sleep(500);
  588. IsPressButton = false;
  589. }))).Start();
  590. }
  591. #endregion
  592. string time = GetTimeStamp();
  593. string tempPath = AppDomain.CurrentDomain.BaseDirectory + "temp\\";
  594. if (!Directory.Exists(tempPath))
  595. {
  596. Directory.CreateDirectory(tempPath);
  597. }
  598. #region 录屏批注取消画笔
  599. //string imagePath = Path.Combine(tempPath, time + ".jpg");
  600. //ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), imagePath, true, out BitmapImage bitmap);
  601. #endregion
  602. try
  603. {
  604. if (flg == 11)
  605. {
  606. Dispatcher.Invoke(() =>
  607. {
  608. borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
  609. borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  610. });
  611. flg = 1;
  612. //this.Owner = null;
  613. APP.W_PracticeWindow.ReturnPractice();
  614. }
  615. else if (flg == 10)
  616. {
  617. Dispatcher.Invoke(() =>
  618. {
  619. borOne.Background = new SolidColorBrush(Colors.LightSkyBlue);
  620. borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  621. });
  622. APP.W_PracticeWindow.Blue();
  623. flg = 11;
  624. }
  625. else
  626. {
  627. //new Thread(new ThreadStart(new Action(() =>
  628. //{
  629. Dispatcher.Invoke(() =>
  630. {
  631. borOne.Background = new SolidColorBrush(Colors.LightSkyBlue);
  632. borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  633. });
  634. //}))).Start();
  635. if (APP.W_PracticeWindow == null)
  636. {
  637. APP.W_PracticeWindow = new PracticeWindow
  638. {
  639. //APP.W_PracticeWindow.Topmost = true;
  640. Width = pwidth,
  641. Height = pHeight,
  642. Left = 0,
  643. Top = 0
  644. };
  645. //practiceWin.Owner = this;
  646. }
  647. APP.W_PracticeWindow.Initialize();// imagePath);
  648. flg = 11;
  649. APP.W_PracticeWindow.Blue();
  650. APP.W_PracticeWindow.Show();
  651. new Thread(new ThreadStart(new Action(() =>
  652. {
  653. Thread.Sleep(100);
  654. Dispatcher.Invoke(() =>
  655. {
  656. this.Owner = APP.W_PracticeWindow;
  657. this.Topmost = true;
  658. });
  659. }))).Start();
  660. }
  661. }
  662. catch (Exception ex)
  663. {
  664. LogHelper.WriteErrLog("【批注(PracticeWindow)" + ex.Message, ex);
  665. }
  666. //imgCanvas.Source = new BitmapImage(new Uri(imagePath));
  667. }
  668. /// <summary>
  669. /// 屏幕宽
  670. /// </summary>
  671. internal double pwidth = SystemParameters.PrimaryScreenWidth;
  672. /// <summary>
  673. /// 屏幕高
  674. /// </summary>
  675. internal double pHeight = SystemParameters.PrimaryScreenHeight;
  676. /// <summary>
  677. /// 获取时间戳
  678. /// </summary>
  679. /// <returns></returns>
  680. public string GetTimeStamp()
  681. {
  682. TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0);
  683. return Convert.ToInt64(ts.TotalMilliseconds).ToString();
  684. }
  685. /// <summary>
  686. /// 画笔粗细事件
  687. /// </summary>
  688. /// <param name="sender"></param>
  689. /// <param name="e"></param>
  690. private void BtnThickness_Click(object sender, RoutedEventArgs e)
  691. {
  692. gridThickness.Visibility = Visibility.Visible;
  693. gridColour.Visibility = Visibility.Collapsed;
  694. }
  695. /// <summary>
  696. /// 画笔颜色事件
  697. /// </summary>
  698. /// <param name="sender"></param>
  699. /// <param name="e"></param>
  700. private void BtnColour_Click(object sender, RoutedEventArgs e)
  701. {
  702. gridColour.Visibility = Visibility.Visible;
  703. gridThickness.Visibility = Visibility.Collapsed;
  704. }
  705. /// <summary>
  706. /// 白色
  707. /// </summary>
  708. /// <param name="sender"></param>
  709. /// <param name="e"></param>
  710. private void BtnWhite_Click(object sender, RoutedEventArgs e)
  711. {
  712. //drawingAttributes.Color = Colors.White;
  713. APP.W_PracticeWindow.White();
  714. gridColour.Visibility = Visibility.Collapsed;
  715. gridThickness.Visibility = Visibility.Collapsed;
  716. }
  717. /// <summary>
  718. /// 红色
  719. /// </summary>
  720. /// <param name="sender"></param>
  721. /// <param name="e"></param>
  722. private void BtnRed_Click(object sender, RoutedEventArgs e)
  723. {
  724. //drawingAttributes.Color = Colors.Red;
  725. APP.W_PracticeWindow.Red();
  726. gridColour.Visibility = Visibility.Collapsed;
  727. gridThickness.Visibility = Visibility.Collapsed;
  728. }
  729. /// <summary>
  730. /// 黄色
  731. /// </summary>
  732. /// <param name="sender"></param>
  733. /// <param name="e"></param>
  734. private void BtnYellow_Click(object sender, RoutedEventArgs e)
  735. {
  736. //drawingAttributes.Color = Colors.Gold;
  737. APP.W_PracticeWindow.Yellow();
  738. gridColour.Visibility = Visibility.Collapsed;
  739. gridThickness.Visibility = Visibility.Collapsed;
  740. }
  741. /// <summary>
  742. /// 青色
  743. /// </summary>
  744. /// <param name="sender"></param>
  745. /// <param name="e"></param>
  746. private void BtnCyanBlue_Click(object sender, RoutedEventArgs e)
  747. {
  748. //drawingAttributes.Color = Colors.LimeGreen;
  749. APP.W_PracticeWindow.CyanBlue();
  750. gridColour.Visibility = Visibility.Collapsed;
  751. gridThickness.Visibility = Visibility.Collapsed;
  752. }
  753. /// <summary>
  754. /// 灰色
  755. /// </summary>
  756. /// <param name="sender"></param>
  757. /// <param name="e"></param>
  758. private void BtnGray_Click(object sender, RoutedEventArgs e)
  759. {
  760. //drawingAttributes.Color = Colors.Gray;
  761. APP.W_PracticeWindow.Gray();
  762. gridColour.Visibility = Visibility.Collapsed;
  763. gridThickness.Visibility = Visibility.Collapsed;
  764. }
  765. /// <summary>
  766. /// 蓝色
  767. /// </summary>
  768. /// <param name="sender"></param>
  769. /// <param name="e"></param>
  770. private void BtnBlue_Click(object sender, RoutedEventArgs e)
  771. {
  772. //drawingAttributes.Color = Colors.DeepSkyBlue;
  773. APP.W_PracticeWindow.Blue();
  774. gridColour.Visibility = Visibility.Collapsed;
  775. gridThickness.Visibility = Visibility.Collapsed;
  776. }
  777. /// <summary>
  778. /// 画笔 细
  779. /// </summary>
  780. /// <param name="sender"></param>
  781. /// <param name="e"></param>
  782. private void BtnFine_Click(object sender, RoutedEventArgs e)
  783. {
  784. APP.W_PracticeWindow.Fine();
  785. gridColour.Visibility = Visibility.Collapsed;
  786. gridThickness.Visibility = Visibility.Collapsed;
  787. }
  788. /// <summary>
  789. /// 画笔 中
  790. /// </summary>
  791. /// <param name="sender"></param>
  792. /// <param name="e"></param>
  793. private void BtnIn_Click(object sender, RoutedEventArgs e)
  794. {
  795. APP.W_PracticeWindow.In();
  796. gridColour.Visibility = Visibility.Collapsed;
  797. gridThickness.Visibility = Visibility.Collapsed;
  798. }
  799. /// <summary>
  800. /// 画笔粗
  801. /// </summary>
  802. /// <param name="sender"></param>
  803. /// <param name="e"></param>
  804. private void BtnCrude_Click(object sender, RoutedEventArgs e)
  805. {
  806. APP.W_PracticeWindow.Crude();
  807. gridColour.Visibility = Visibility.Collapsed;
  808. gridThickness.Visibility = Visibility.Collapsed;
  809. }
  810. /// <summary>
  811. /// 橡皮
  812. /// </summary>
  813. /// <param name="sender"></param>
  814. /// <param name="e"></param>
  815. private void BtnEraser_Click(object sender, RoutedEventArgs e)
  816. {
  817. APP.W_PracticeWindow.Eraser();
  818. }
  819. /// <summary>
  820. /// 🖊
  821. /// </summary>
  822. /// <param name="sender"></param>
  823. /// <param name="e"></param>
  824. private void BtnPen_Click(object sender, RoutedEventArgs e)
  825. {
  826. APP.W_PracticeWindow.Pen();
  827. }
  828. /// <summary>
  829. /// ⚪
  830. /// </summary>
  831. /// <param name="sender"></param>
  832. /// <param name="e"></param>
  833. private void BtnRound_Click(object sender, RoutedEventArgs e)
  834. {
  835. APP.W_PracticeWindow.Round();
  836. }
  837. /// <summary>
  838. /// 矩形
  839. /// </summary>
  840. /// <param name="sender"></param>
  841. /// <param name="e"></param>
  842. private void BtnRectangle_Click(object sender, RoutedEventArgs e)
  843. {
  844. APP.W_PracticeWindow.Rectangle();
  845. }
  846. #endregion
  847. #endregion
  848. /// <summary>
  849. /// 停止录屏
  850. /// </summary>
  851. public delegate void StopRecordingScreen();
  852. /// <summary>
  853. /// 停止录屏
  854. /// </summary>
  855. public event StopRecordingScreen Click_stopRecordingScreen;
  856. /// <summary>
  857. /// 黑笔
  858. /// </summary>
  859. /// <param name="sender"></param>
  860. /// <param name="e"></param>
  861. private void BtnBlackPen_Click(object sender, RoutedEventArgs e)
  862. {
  863. }
  864. /// <summary>
  865. /// 移动工具栏
  866. /// </summary>
  867. /// <param name="sender"></param>
  868. /// <param name="e"></param>
  869. private void Grid_MouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
  870. {
  871. DragMove();
  872. }
  873. /// <summary>
  874. /// 红笔
  875. /// </summary>
  876. /// <param name="sender"></param>
  877. /// <param name="e"></param>
  878. private void BtnBlackPenTwo_Click(object sender, RoutedEventArgs e)
  879. {
  880. #region 防止连击
  881. if (IsPressButton)
  882. {
  883. return;
  884. }
  885. else
  886. {
  887. IsPressButton = true;
  888. new Thread(new ThreadStart(new Action(() =>
  889. {
  890. Thread.Sleep(500);
  891. IsPressButton = false;
  892. }))).Start();
  893. }
  894. #endregion
  895. string time = GetTimeStamp();
  896. string tempPath = AppDomain.CurrentDomain.BaseDirectory + "temp\\";
  897. if (!Directory.Exists(tempPath))
  898. {
  899. Directory.CreateDirectory(tempPath);
  900. }
  901. #region 录屏批注取消画笔
  902. string imagePath = Path.Combine(tempPath, time + ".jpg");
  903. ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), imagePath, true, out BitmapImage bitmap);
  904. #endregion
  905. try
  906. {
  907. if (flg == 10)
  908. {
  909. Dispatcher.Invoke(() =>
  910. {
  911. borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
  912. borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  913. });
  914. flg = 0;
  915. //this.Owner = null;
  916. APP.W_PracticeWindow.ReturnPractice();
  917. }
  918. else if (flg == 11)
  919. {
  920. Dispatcher.Invoke(() =>
  921. {
  922. borTwo.Background = new SolidColorBrush(Colors.LightSkyBlue);
  923. borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
  924. });
  925. flg = 10;
  926. APP.W_PracticeWindow.Red();
  927. }
  928. else
  929. {
  930. Dispatcher.Invoke(() =>
  931. {
  932. borTwo.Background = new SolidColorBrush(Colors.LightSkyBlue);
  933. borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
  934. });
  935. if (APP.W_PracticeWindow == null)
  936. {
  937. APP.W_PracticeWindow = new PracticeWindow
  938. {
  939. //APP.W_PracticeWindow.Topmost = true;
  940. Width = pwidth,
  941. Height = pHeight,
  942. Left = 0,
  943. Top = 0
  944. };
  945. //practiceWin.Owner = this;
  946. }
  947. APP.W_PracticeWindow.Initialize();//imagePath);
  948. flg = 10;
  949. APP.W_PracticeWindow.Red();
  950. APP.W_PracticeWindow.Show();
  951. new Thread(new ThreadStart(new Action(() =>
  952. {
  953. Thread.Sleep(100);
  954. Dispatcher.Invoke(() =>
  955. {
  956. this.Owner = APP.W_PracticeWindow;
  957. this.Topmost = true;
  958. });
  959. }))).Start();
  960. }
  961. }
  962. catch (Exception ex)
  963. {
  964. LogHelper.WriteErrLog("【批注(PracticeWindow)" + ex.Message, ex);
  965. }
  966. }
  967. /// <summary>
  968. /// 鼠标右键按下事件 废弃
  969. /// </summary>
  970. /// <param name="sender"></param>
  971. /// <param name="e"></param>
  972. private void RightButtonDown()
  973. {
  974. if (flg > 9)
  975. {
  976. this.Owner = null;
  977. APP.W_PracticeWindow.Hide();
  978. }
  979. else
  980. {
  981. //string time = GetTimeStamp();
  982. string tempPath = AppDomain.CurrentDomain.BaseDirectory + "temp\\";
  983. if (!Directory.Exists(tempPath))
  984. {
  985. Directory.CreateDirectory(tempPath);
  986. }
  987. #region 录屏批注取消画笔
  988. //string imagePath = Path.Combine(tempPath, time + ".jpg");
  989. //ImageHelper.GetScreenshot(new System.Drawing.Rectangle(0, 0, 0, 0), imagePath, true, out BitmapImage bitmap);
  990. #endregion
  991. try
  992. {
  993. if (APP.W_PracticeWindow == null)
  994. {
  995. APP.W_PracticeWindow = new PracticeWindow
  996. {
  997. //APP.W_PracticeWindow.Topmost = true;
  998. Width = pwidth,
  999. Height = pHeight,
  1000. Left = 0,
  1001. Top = 0
  1002. };
  1003. //practiceWin.Owner = this;
  1004. }
  1005. APP.W_PracticeWindow.Initialize();//imagePath);
  1006. if (flg == 0)
  1007. {
  1008. flg = 10;
  1009. APP.W_PracticeWindow.Red();
  1010. }
  1011. else
  1012. {
  1013. flg = 11;
  1014. APP.W_PracticeWindow.Blue();
  1015. }
  1016. APP.W_PracticeWindow.Show();
  1017. }
  1018. catch (Exception ex)
  1019. {
  1020. LogHelper.WriteErrLog("【批注(PracticeWindow)" + ex.Message, ex);
  1021. }
  1022. }
  1023. }
  1024. /// <summary>
  1025. /// 返回主界面
  1026. /// </summary>
  1027. /// <param name="sender"></param>
  1028. /// <param name="e"></param>
  1029. private void BtnReturn_Click(object sender, RoutedEventArgs e)
  1030. {
  1031. if (!IsFirstRS)
  1032. {
  1033. MessageBoxResult br = MessageWindow.Show("退出将不保存当前录屏!", "提示", MessageBoxButton.OKCancel);
  1034. if (br == MessageBoxResult.Cancel)
  1035. {
  1036. return;
  1037. }
  1038. k_hook.Stop();
  1039. IsSuspend = true;
  1040. txbTime.Text = "00:00";
  1041. txbTime.Visibility = Visibility.Hidden;
  1042. End();
  1043. if (APP.W_PracticeWindow != null)
  1044. {
  1045. if (APP.W_PracticeWindow.Visibility == Visibility.Visible)
  1046. {
  1047. APP.W_PracticeWindow.Hide();
  1048. }
  1049. }
  1050. if (gridToolbar.Visibility == Visibility.Visible)
  1051. {
  1052. gridToolbar.Visibility = Visibility.Hidden;
  1053. gridColour.Visibility = Visibility.Hidden;
  1054. gridThickness.Visibility = Visibility.Hidden;
  1055. }
  1056. if (APP.W_XHMicroLessonSystemWindow == null)
  1057. {
  1058. APP.W_XHMicroLessonSystemWindow = new XHMicroLessonSystemWindow();
  1059. }
  1060. try
  1061. {
  1062. try
  1063. {
  1064. APP.FFmpeg.SuspendFFmpeg();
  1065. }
  1066. catch (Exception ex)
  1067. {
  1068. LogHelper.WriteErrLog("【录屏返回】(BtnStopRecordingScreen_Click)" + ex.Message, ex);
  1069. }
  1070. IsFirstRS = true;
  1071. new Thread(new ThreadStart(new Action(() =>
  1072. {
  1073. VideoInfo = null;
  1074. FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temprs/");
  1075. }))).Start();
  1076. }
  1077. catch (Exception ex)
  1078. {
  1079. LogHelper.WriteErrLog("【录屏返回】(BtnStopRecordingScreen_Click)" + ex.Message, ex);
  1080. }
  1081. }
  1082. APP.W_XHMicroLessonSystemWindow.InitializeKeyDownEvent();
  1083. APP.W_XHMicroLessonSystemWindow.Show();
  1084. Hide();
  1085. }
  1086. /// <summary>
  1087. /// 批注退出 废弃
  1088. /// </summary>
  1089. public void ReturnPractice()
  1090. {
  1091. new Thread(new ThreadStart(new Action(() =>
  1092. {
  1093. Dispatcher.Invoke(() =>
  1094. {
  1095. borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
  1096. borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  1097. });
  1098. flg = 0;
  1099. Thread.Sleep(500);
  1100. Dispatcher.Invoke(() =>
  1101. {
  1102. this.Owner = null;
  1103. APP.W_PracticeWindow.Hide();
  1104. });
  1105. }))).Start();
  1106. //Dispatcher.Invoke(() =>
  1107. //{
  1108. // borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
  1109. // borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  1110. //});
  1111. //flg = 0;
  1112. //Thread.Sleep(300);
  1113. //APP.W_PracticeWindow.Hide();
  1114. }
  1115. /// <summary>
  1116. /// 修改笔状态
  1117. /// </summary>
  1118. public void ModifyState()
  1119. {
  1120. borOne.Background = new SolidColorBrush(Colors.DodgerBlue);
  1121. borTwo.Background = new SolidColorBrush(Colors.DodgerBlue);
  1122. }
  1123. }
  1124. }