Преглед на файлове

zhao:1修改录屏检测麦克风和扬声器 2录屏返回可以取消并不保存录屏3解决太快操作录屏冲突。

tags/录制修改前
耀 преди 4 години
родител
ревизия
d2054fa54d
променени са 3 файла, в които са добавени 105 реда и са изтрити 24 реда
  1. 40
    15
      Common/system/FFMpeg.cs
  2. 60
    7
      XHWK.WKTool/ScreenRecordingToolbarWindow.xaml.cs
  3. 5
    2
      XHWK.WKTool/XHMicroLessonSystemWindow.xaml.cs

+ 40
- 15
Common/system/FFMpeg.cs Целия файл

@@ -77,18 +77,18 @@ namespace Common.system
77 77
                 //无法录制扬声器音频
78 78
                 IsRecordSpeaker = false;
79 79
             }
80
-            StopRecordAudio();
81
-            Thread.Sleep(500);
80
+            StopRecordAudio(2);
81
+            Thread.Sleep(100);
82 82
             if (StartRecordAudio(audioMicrophonePath))
83 83
             {
84 84
                 IsRecordMicrophone = true;
85 85
             }
86 86
             else
87 87
             {
88
-                //无法录制扬声器
88
+                //无法录制麦克风
89 89
                 IsRecordMicrophone = false;
90 90
             }
91
-            StopRecordAudio();
91
+            StopRecordAudio(1);
92 92
             #endregion
93 93
             myProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath(@"/ffmpeg/bin/ffmpeg.exe");   //ffmpeg.exe的绝对路径
94 94
             string SpeakerStr = "";
@@ -186,8 +186,8 @@ namespace Common.system
186 186
                 //无法录制扬声器音频
187 187
                 IsRecordSpeaker = false;
188 188
             }
189
-            StopRecordAudio();
190
-            Thread.Sleep(500);
189
+            StopRecordAudio(2);
190
+            Thread.Sleep(100);
191 191
             if (StartRecordAudio(audioMicrophonePath))
192 192
             {
193 193
                 IsRecordMicrophone = true;
@@ -195,10 +195,10 @@ namespace Common.system
195 195
             }
196 196
             else
197 197
             {
198
-                //无法录制扬声器
198
+                //无法录制麦克风
199 199
                 IsRecordMicrophone = false;
200 200
             }
201
-            StopRecordAudio();
201
+            StopRecordAudio(1);
202 202
             if (!IsRecordSpeaker && !IsRecordMicrophone)
203 203
             {
204 204
                 return false;
@@ -811,7 +811,9 @@ namespace Common.system
811 811
             return devs;
812 812
         }
813 813
 
814
-        //录制麦克风的声音
814
+        /// <summary>
815
+        /// 录制麦克风的声音
816
+        /// </summary>
815 817
         private WaveInEvent waveIn = null; //new WaveInEvent();
816 818
         /// <summary>
817 819
         /// 开始录制麦克风
@@ -858,17 +860,38 @@ namespace Common.system
858 860
         /// <summary>
859 861
         /// 结束录制音频
860 862
         /// </summary>
861
-        public void StopRecordAudio()
863
+        /// <param name="type">1麦克风 2扬声器</param>
864
+        public void StopRecordAudio(int type)
862 865
         {
863 866
             try
864 867
             {
865
-                if (waveIn != null)
868
+                if (type == 1)
866 869
                 {
867
-                    waveIn.StopRecording();
870
+                    if (waveIn != null)
871
+                    {
872
+                        try
873
+                        {
874
+                            waveIn.StopRecording();
875
+                        }
876
+                        catch (Exception ex)
877
+                        {
878
+                            waveIn = null;
879
+                        }
880
+                    }
868 881
                 }
869
-                if (capture != null)
882
+                else if (type == 2)
870 883
                 {
871
-                    capture.StopRecording();
884
+                    if (capture != null)
885
+                    {
886
+                        try
887
+                        {
888
+                            capture.StopRecording();
889
+                        }
890
+                        catch (Exception)
891
+                        {
892
+                            capture = null;
893
+                        }
894
+                    }
872 895
                 }
873 896
             }
874 897
             catch (Exception ex)
@@ -878,7 +901,9 @@ namespace Common.system
878 901
         }
879 902
 
880 903
 
881
-        //录制扬声器的声音
904
+        /// <summary>
905
+        /// 录制扬声器的声音
906
+        /// </summary>
882 907
         private WasapiLoopbackCapture capture = null; //new WasapiLoopbackCapture();
883 908
 
884 909
         /// <summary>

+ 60
- 7
XHWK.WKTool/ScreenRecordingToolbarWindow.xaml.cs Целия файл

@@ -107,8 +107,8 @@ namespace XHWK.WKTool
107 107
             btnBlackPenOne.IsEnabled = false;//蓝笔不可点击
108 108
             imgBlackPenTwo.Source = new BitmapImage(new Uri("pack://application:,,,/Images/31.png"));
109 109
             btnBlackPenTwo.IsEnabled = false;//红笔不可点击
110
-            imgReturn.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar29.png"));
111
-            btnReturn.IsEnabled = true;//返回主界面可点击
110
+            //imgReturn.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar29.png"));
111
+            //btnReturn.IsEnabled = true;//返回主界面可点击
112 112
             txbTime.Visibility = Visibility.Hidden;//时间不显示
113 113
             if (t == null)
114 114
             {
@@ -232,7 +232,7 @@ namespace XHWK.WKTool
232 232
         {
233 233
             //FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temp/");
234 234
             FileToolsCommon.CreateDirectory(APP.WKData.WkPath);
235
-            FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "tempsr/");
235
+            FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temprs/");
236 236
             VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录屏." + ((Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType"))).ToString();
237 237
             int num = 1;
238 238
             while (FileToolsCommon.IsExistFile(VideoSavePathName))
@@ -267,7 +267,7 @@ namespace XHWK.WKTool
267 267
                     //扬声器
268 268
                     if (APP.FFmpeg.StartRecordSpeakerAudio(audioSpeakerPath))
269 269
                     {
270
-                        APP.FFmpeg.StopRecordAudio();
270
+                        APP.FFmpeg.StopRecordAudio(2);
271 271
                         //Thread.Sleep(500);
272 272
                         //麦克风
273 273
                         if (APP.FFmpeg.StartRecordAudio(audioMicrophonePath))
@@ -282,7 +282,7 @@ namespace XHWK.WKTool
282 282
                                 return;
283 283
                             }
284 284
                         }
285
-                        APP.FFmpeg.StopRecordAudio();
285
+                        APP.FFmpeg.StopRecordAudio(1);
286 286
                     }
287 287
                     else
288 288
                     {
@@ -341,8 +341,8 @@ namespace XHWK.WKTool
341 341
                 btnBlackPenOne.IsEnabled = true;//蓝笔可点击
342 342
                 imgBlackPenTwo.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar28.png"));
343 343
                 btnBlackPenTwo.IsEnabled = true;//红笔可点击
344
-                imgReturn.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar30.png"));
345
-                btnReturn.IsEnabled = false;//返回主界面不可点击
344
+                //imgReturn.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar30.png"));
345
+                //btnReturn.IsEnabled = false;//返回主界面不可点击
346 346
                 txbTime.Visibility = Visibility.Visible;//时间显示
347 347
                 try
348 348
                 {
@@ -352,6 +352,10 @@ namespace XHWK.WKTool
352 352
                         {
353 353
                             Thread.Sleep(1500);
354 354
                         }
355
+                        if(APP.FFmpeg.myProcess!=null)
356
+                        {
357
+                            Thread.Sleep(100);
358
+                        }
355 359
                         APP.FFmpeg.StartRecordingVideo(VideoSavePathName);
356 360
 
357 361
                         Thread.Sleep(1000);
@@ -876,11 +880,60 @@ namespace XHWK.WKTool
876 880
         /// <param name="e"></param>
877 881
         private void BtnReturn_Click(object sender, RoutedEventArgs e)
878 882
         {
883
+            MessageBoxResult br=MessageWindow.Show("退出将不保存当前录屏!", "提示", MessageBoxButton.OKCancel);
884
+            if(br==MessageBoxResult.Cancel)
885
+            {
886
+                return;
887
+            }
888
+            k_hook.Stop();
889
+            IsSuspend = true;
890
+            txbTime.Text = "00:00";
891
+
892
+            txbTime.Visibility = Visibility.Hidden;
893
+            End();
894
+            if (APP.W_PracticeWindow != null)
895
+            {
896
+                if (APP.W_PracticeWindow.Visibility == Visibility.Visible)
897
+                {
898
+                    APP.W_PracticeWindow.Hide();
899
+                }
900
+            }
901
+            if (gridToolbar.Visibility == Visibility.Visible)
902
+            {
903
+                gridToolbar.Visibility = Visibility.Hidden;
904
+                gridColour.Visibility = Visibility.Hidden;
905
+                gridThickness.Visibility = Visibility.Hidden;
906
+            }
879 907
             if (APP.W_XHMicroLessonSystemWindow == null)
880 908
             {
881 909
                 APP.W_XHMicroLessonSystemWindow = new XHMicroLessonSystemWindow();
882 910
             }
883 911
             APP.W_XHMicroLessonSystemWindow.Show();
912
+            if (!IsFirstRS)
913
+            {
914
+                try
915
+                {
916
+                    try
917
+                    {
918
+                        APP.FFmpeg.SuspendFFmpeg();
919
+                    }
920
+                    catch (Exception ex)
921
+                    {
922
+                        LogHelper.WriteErrLog("【录屏返回】(BtnStopRecordingScreen_Click)" + ex.Message, ex);
923
+                    }
924
+                    IsFirstRS = true;
925
+                    new Thread(new ThreadStart(new Action(() =>
926
+                    {
927
+                        VideoInfo = null;
928
+                        FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temprs/");
929
+                        
930
+                    }))).Start();
931
+                }
932
+                catch (Exception ex)
933
+                {
934
+                    LogHelper.WriteErrLog("【录屏返回】(BtnStopRecordingScreen_Click)" + ex.Message, ex);
935
+                }
936
+            }
884 937
             Hide();
885 938
         }
886 939
     }

+ 5
- 2
XHWK.WKTool/XHMicroLessonSystemWindow.xaml.cs Целия файл

@@ -2056,6 +2056,7 @@ namespace XHWK.WKTool
2056 2056
                 {
2057 2057
                     Thread.Sleep(100);
2058 2058
                 }
2059
+                Thread.Sleep(100);
2059 2060
                 Dispatcher.Invoke(() =>
2060 2061
                 {
2061 2062
                     btnScreenRecording.IsEnabled = true;
@@ -2139,7 +2140,7 @@ namespace XHWK.WKTool
2139 2140
                     //扬声器
2140 2141
                     if (APP.FFmpeg.StartRecordSpeakerAudio(audioSpeakerPath))
2141 2142
                     {
2142
-                        APP.FFmpeg.StopRecordAudio();
2143
+                        APP.FFmpeg.StopRecordAudio(2);
2143 2144
                         //Thread.Sleep(500);
2144 2145
                         //麦克风
2145 2146
                         if (APP.FFmpeg.StartRecordAudio(audioMicrophonePath))
@@ -2154,7 +2155,7 @@ namespace XHWK.WKTool
2154 2155
                                 return;
2155 2156
                             }
2156 2157
                         }
2157
-                        APP.FFmpeg.StopRecordAudio();
2158
+                        APP.FFmpeg.StopRecordAudio(1);
2158 2159
                     }
2159 2160
                     else
2160 2161
                     {
@@ -2288,6 +2289,7 @@ namespace XHWK.WKTool
2288 2289
                     IsFirstR = false;
2289 2290
                     RsImgName = new List<string>();
2290 2291
                     SRTime = Convert.ToDateTime("2020-01-01 00:00:00");
2292
+                    txbTime.Visibility = Visibility.Visible;
2291 2293
                     ///启动截图
2292 2294
                     timer = new System.Threading.Timer(new TimerCallback(Timer_Elapsed), null, 0, 20);
2293 2295
                     //{
@@ -2493,6 +2495,7 @@ namespace XHWK.WKTool
2493 2495
                 ImgStop.Visibility = Visibility.Visible;
2494 2496
                 ImgStopTwo.Visibility = Visibility.Collapsed;
2495 2497
                 //TimeOut();
2498
+                txbType.Visibility = Visibility.Visible;
2496 2499
                 txbType.Text = "保存中";
2497 2500
                 #region 2秒内不可点击
2498 2501
                 new Thread(new ThreadStart(new Action(() =>

Loading…
Отказ
Запис