星火微课系统客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ScreenRecordingToolbarWindow.xaml.cs 42KB

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