Преглед изворни кода

zhao:1优化录制录屏2完善日志,增加杀毒软件拦截报告

tags/录制修改前
耀 пре 4 година
родитељ
комит
4d1ad3e54c

+ 72
- 11
Common/system/FFMpeg.cs Прегледај датотеку

@@ -6,6 +6,7 @@ using System.IO;
6 6
 using System.Linq;
7 7
 using System.Text;
8 8
 using System.Threading;
9
+using System.Windows.Forms;
9 10
 
10 11
 using VisioForge.Shared.NAudio.CoreAudioApi;
11 12
 using VisioForge.Shared.NAudio.Wave;
@@ -45,12 +46,13 @@ namespace Common.system
45 46
         /// 录制屏幕
46 47
         /// </summary>
47 48
         /// <param name="FilePath">文件存储路径</param>
48
-        public void StartRecordingVideo(string FilePath)
49
+        public bool StartRecordingVideo(string FilePath,out string ErrMessage)
49 50
         {
50 51
             while (myProcess != null)
51 52
             {
52 53
                 Thread.Sleep(100);
53 54
             }
55
+            ErrMessage = null;
54 56
             //路径
55 57
             string Path = FileToolsCommon.GetDirectoryName(FilePath);
56 58
             string Extension = FileToolsCommon.GetIOExtension(FilePath);//扩展名
@@ -155,16 +157,36 @@ namespace Common.system
155 157
             myProcess.StartInfo.CreateNoWindow = true;             //不显示程序窗口
156 158
             myProcess.StartInfo.RedirectStandardInput = true;      //用于模拟该进程控制台的输入
157 159
             myProcess.ErrorDataReceived += new DataReceivedEventHandler(Output);
158
-            myProcess.Start();
159
-            myProcess.BeginErrorReadLine();
160
+            try
161
+            {
162
+                myProcess.Start();
163
+                myProcess.BeginErrorReadLine();
164
+            }
165
+            catch (Exception ex)
166
+            {
167
+                if (ex.Message.Contains("访问"))
168
+                {
169
+                    ErrMessage = "访问被拒绝,请关闭杀毒软件或新任此软件后重试!";
170
+                }
171
+                else
172
+                {
173
+                    ErrMessage = ex.Message + " 请关闭杀毒软件或信任此软件后重试!";
174
+                }
175
+                LogHelper.WriteErrLog("【录音】(StartRecordingAudio)" + ErrMessage, ex);
176
+                myProcess.Dispose();
177
+                myProcess = null;
178
+                return false;
179
+            }
180
+            return true;
160 181
         }
161 182
 
162 183
         /// <summary>
163 184
         /// 录制音频
164 185
         /// </summary>
165 186
         /// <param name="Mp3Path">MP3音频位置</param>
166
-        public bool StartRecordingAudio(string Mp3Path)
187
+        public bool StartRecordingAudio(string Mp3Path,out string ErrMessage)
167 188
         {
189
+            ErrMessage = null;
168 190
             while (myProcess != null)
169 191
             {
170 192
                 Thread.Sleep(100);
@@ -215,6 +237,7 @@ namespace Common.system
215 237
             StopRecordAudio(1);
216 238
             if (!IsRecordSpeaker && !IsRecordMicrophone)
217 239
             {
240
+                ErrMessage = "无法录制声音,请关闭杀毒软件,确保声卡和麦克风处于可用状态!";
218 241
                 return false;
219 242
             }
220 243
             #endregion
@@ -248,8 +271,26 @@ namespace Common.system
248 271
             myProcess.StartInfo.RedirectStandardInput = true;    //用于模拟该进程控制台的输入
249 272
             //外部程序(这里是FFMPEG)输出流时候产生的事件,这里是把流的处理过程转移到下面的方法中,详细请查阅MSDN
250 273
             myProcess.ErrorDataReceived += new DataReceivedEventHandler(Output);
251
-            myProcess.Start();                //启动线程
252
-            myProcess.BeginErrorReadLine();   //开始异步读取
274
+            try
275
+            {
276
+                myProcess.Start();                //启动线程
277
+                myProcess.BeginErrorReadLine();   //开始异步读取
278
+            }
279
+            catch (Exception ex)
280
+            {
281
+                if (ex.Message.Contains("访问"))
282
+                {
283
+                    ErrMessage = "无法录制声音,访问被拒绝,请关闭杀毒软件或信任此软件后重试!";
284
+                }
285
+                else
286
+                {
287
+                    ErrMessage = ex.Message+" 请关闭杀毒软件或信任此软件后重试!";
288
+                }
289
+                LogHelper.WriteErrLog("【录音】(StartRecordingAudio)"+ErrMessage,ex);
290
+                myProcess.Dispose();
291
+                myProcess = null;
292
+                return false;
293
+            }
253 294
             return true;
254 295
         }
255 296
 
@@ -324,7 +365,7 @@ namespace Common.system
324 365
         /// <param name="Frequency">每秒帧率</param>
325 366
         /// <param name="VideoWidth">视频宽度</param>
326 367
         /// <param name="VideoHeight">视频高度</param>
327
-        public bool SynthesisVideo(string ImageListPath, string Mp3Path, string VideoSavePath, int Frequency, int VideoWidth, int VideoHeight)
368
+        public bool SynthesisVideo(string ImageListPath, string Mp3Path, string VideoSavePath, int Frequency, int VideoWidth, int VideoHeight,out string ErrMessage)
328 369
         {
329 370
             //new Thread(new ThreadStart(new Action(() =>
330 371
             //{
@@ -334,6 +375,7 @@ namespace Common.system
334 375
             {
335 376
                 Thread.Sleep(100);
336 377
             }
378
+            ErrMessage = null;
337 379
             string Extension = FileToolsCommon.GetIOExtension(VideoSavePath);//扩展名
338 380
             Process[] KillProcessArray = Process.GetProcessesByName("ffmpeg");
339 381
             //Debug.WriteLine(KillProcessArray.Length.ToString());
@@ -393,10 +435,28 @@ namespace Common.system
393 435
                 myProcess.StartInfo.RedirectStandardInput = true;      //用于模拟该进程控制台的输入
394 436
                                                                        //外部程序(这里是FFMPEG)输出流时候产生的事件,这里是把流的处理过程转移到下面的方法中,详细请查阅MSDN
395 437
                 myProcess.ErrorDataReceived += new DataReceivedEventHandler(Output);
396
-                myProcess.Start();                 //启动线程
397
-                myProcess.BeginErrorReadLine();    //开始异步读取
398
-                myProcess.WaitForExit();           //阻塞等待进程结束
399
-                myProcess.Close();                 //关闭进程
438
+                try
439
+                {
440
+                    myProcess.Start();                 //启动线程
441
+                    myProcess.BeginErrorReadLine();    //开始异步读取
442
+                    myProcess.WaitForExit();           //阻塞等待进程结束
443
+                    myProcess.Close();                 //关闭进程
444
+                }
445
+                catch (Exception ex)
446
+                {
447
+                    if (ex.Message.Contains("访问"))
448
+                    {
449
+                        ErrMessage = "访问被拒绝,请关闭杀毒软件或新任此软件后重试!";
450
+                    }
451
+                    else
452
+                    {
453
+                        ErrMessage = ex.Message + " 请关闭杀毒软件或信任此软件后重试!";
454
+                    }
455
+                    LogHelper.WriteErrLog("【录音】(StartRecordingAudio)" + ErrMessage, ex);
456
+                    myProcess.Dispose();
457
+                    myProcess = null;
458
+                    return false;
459
+                }
400 460
                 myProcess.Dispose();               //释放资源
401 461
                 #region 进程是否已经释放
402 462
                 bool IsRunning = true;
@@ -423,6 +483,7 @@ namespace Common.system
423 483
             catch (Exception ex)
424 484
             {
425 485
                 LogHelper.WriteErrLog("【视频合成】(SynthesisVideo)视频生成失败," + ex.Message, ex);
486
+                ErrMessage = ex.Message;
426 487
                 return false;
427 488
             }
428 489
             //Dispatcher.Invoke(() =>

+ 22
- 1
XHWK.WKTool/ScreenRecordingToolbarWindow.xaml.cs Прегледај датотеку

@@ -424,11 +424,32 @@ namespace XHWK.WKTool
424 424
                         {
425 425
                             Thread.Sleep(100);
426 426
                         }
427
-                        APP.FFmpeg.StartRecordingVideo(VideoSavePathName);
427
+                        bool SynRes=APP.FFmpeg.StartRecordingVideo(VideoSavePathName,out string ErrMessage);
428 428
 
429 429
                         Thread.Sleep(1300);
430 430
                         Dispatcher.Invoke(() =>
431 431
                         {
432
+                            if(!SynRes)
433
+                            {
434
+                                MessageWindow.Show(ErrMessage);
435
+                                //隐藏画笔工具栏
436
+                                //BtnToolbarDown_Click(null, null);
437
+                                gridToolbar.Visibility = Visibility.Hidden;
438
+                                gridColour.Visibility = Visibility.Hidden;
439
+                                gridThickness.Visibility = Visibility.Hidden;
440
+                                ImgRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar26.png"));//大圆圈三角形
441
+                                ImgEndRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar15.png"));
442
+                                BtnStopRecordingScreen.IsEnabled = false; //停止录制按钮不点击
443
+                                imgBlackPenOne.Source = new BitmapImage(new Uri("pack://application:,,,/Images/31.png"));
444
+                                btnBlackPenOne.IsEnabled = false;//蓝笔不可点击
445
+                                imgBlackPenTwo.Source = new BitmapImage(new Uri("pack://application:,,,/Images/31.png"));
446
+                                btnBlackPenTwo.IsEnabled = false;//红笔不可点击
447
+                                txbTime.Visibility = Visibility.Hidden;//时间不显示
448
+                                BtnRecordingScreen.ToolTip = "开始";
449
+                                IsSuspend = true;
450
+                                IsFirstRS = true;
451
+                                return;
452
+                            }
432 453
                             Stack();
433 454
                         });
434 455
                     }))).Start();

+ 8
- 3
XHWK.WKTool/XHMicroLessonSystemWindow.xaml.cs Прегледај датотеку

@@ -3092,10 +3092,14 @@ namespace XHWK.WKTool
3092 3092
                     new Thread(new ThreadStart(new Action(() =>
3093 3093
                     {
3094 3094
                         Thread.Sleep(1000);
3095
-                        IsRecordAudio = APP.FFmpeg.StartRecordingAudio(AudioPathName);
3095
+                        IsRecordAudio = APP.FFmpeg.StartRecordingAudio(AudioPathName,out string ErrMessage);
3096 3096
                         Thread.Sleep(1000);
3097 3097
                         Dispatcher.Invoke(() =>
3098 3098
                         {
3099
+                            if(!IsRecordAudio)
3100
+                            {
3101
+                                MessageWindow.Show(ErrMessage);
3102
+                            }
3099 3103
                             Recorddt = DateTime.Now;
3100 3104
                             IsStartCount = true;
3101 3105
                             //Stack();
@@ -3361,7 +3365,7 @@ namespace XHWK.WKTool
3361 3365
                                 AudioPathName = null;
3362 3366
                             }
3363 3367
                             //合成视频
3364
-                            bool SynRes = APP.FFmpeg.SynthesisVideo(ImgPath, AudioPathName, VideoSynthesisPathName, 5, gridActWidth, gridActHeight);
3368
+                            bool SynRes = APP.FFmpeg.SynthesisVideo(ImgPath, AudioPathName, VideoSynthesisPathName, 5, gridActWidth, gridActHeight,out string ErrMessage);
3365 3369
                             //}))).Start();
3366 3370
                             //new Thread(new ThreadStart(new Action(() =>
3367 3371
                             //{
@@ -3369,7 +3373,8 @@ namespace XHWK.WKTool
3369 3373
                             {
3370 3374
                                 Dispatcher.Invoke(() =>
3371 3375
                                 {
3372
-                                    MessageWindow.Show("视频录制失败,无法保存此视频!");
3376
+                                    //MessageWindow.Show("视频录制失败,无法保存此视频!");
3377
+                                    MessageWindow.Show("录制失败,"+ErrMessage);
3373 3378
                                     BtnRecord.IsEnabled = true;
3374 3379
                                     btnStop.IsEnabled = true;
3375 3380
                                     TxbRecordingWord.Text = "录制";

Loading…
Откажи
Сачувај