Browse Source

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

tags/录制修改前
耀 4 years ago
parent
commit
d2054fa54d

+ 40
- 15
Common/system/FFMpeg.cs View File

77
                 //无法录制扬声器音频
77
                 //无法录制扬声器音频
78
                 IsRecordSpeaker = false;
78
                 IsRecordSpeaker = false;
79
             }
79
             }
80
-            StopRecordAudio();
81
-            Thread.Sleep(500);
80
+            StopRecordAudio(2);
81
+            Thread.Sleep(100);
82
             if (StartRecordAudio(audioMicrophonePath))
82
             if (StartRecordAudio(audioMicrophonePath))
83
             {
83
             {
84
                 IsRecordMicrophone = true;
84
                 IsRecordMicrophone = true;
85
             }
85
             }
86
             else
86
             else
87
             {
87
             {
88
-                //无法录制扬声器
88
+                //无法录制麦克风
89
                 IsRecordMicrophone = false;
89
                 IsRecordMicrophone = false;
90
             }
90
             }
91
-            StopRecordAudio();
91
+            StopRecordAudio(1);
92
             #endregion
92
             #endregion
93
             myProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath(@"/ffmpeg/bin/ffmpeg.exe");   //ffmpeg.exe的绝对路径
93
             myProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath(@"/ffmpeg/bin/ffmpeg.exe");   //ffmpeg.exe的绝对路径
94
             string SpeakerStr = "";
94
             string SpeakerStr = "";
186
                 //无法录制扬声器音频
186
                 //无法录制扬声器音频
187
                 IsRecordSpeaker = false;
187
                 IsRecordSpeaker = false;
188
             }
188
             }
189
-            StopRecordAudio();
190
-            Thread.Sleep(500);
189
+            StopRecordAudio(2);
190
+            Thread.Sleep(100);
191
             if (StartRecordAudio(audioMicrophonePath))
191
             if (StartRecordAudio(audioMicrophonePath))
192
             {
192
             {
193
                 IsRecordMicrophone = true;
193
                 IsRecordMicrophone = true;
195
             }
195
             }
196
             else
196
             else
197
             {
197
             {
198
-                //无法录制扬声器
198
+                //无法录制麦克风
199
                 IsRecordMicrophone = false;
199
                 IsRecordMicrophone = false;
200
             }
200
             }
201
-            StopRecordAudio();
201
+            StopRecordAudio(1);
202
             if (!IsRecordSpeaker && !IsRecordMicrophone)
202
             if (!IsRecordSpeaker && !IsRecordMicrophone)
203
             {
203
             {
204
                 return false;
204
                 return false;
811
             return devs;
811
             return devs;
812
         }
812
         }
813
 
813
 
814
-        //录制麦克风的声音
814
+        /// <summary>
815
+        /// 录制麦克风的声音
816
+        /// </summary>
815
         private WaveInEvent waveIn = null; //new WaveInEvent();
817
         private WaveInEvent waveIn = null; //new WaveInEvent();
816
         /// <summary>
818
         /// <summary>
817
         /// 开始录制麦克风
819
         /// 开始录制麦克风
858
         /// <summary>
860
         /// <summary>
859
         /// 结束录制音频
861
         /// 结束录制音频
860
         /// </summary>
862
         /// </summary>
861
-        public void StopRecordAudio()
863
+        /// <param name="type">1麦克风 2扬声器</param>
864
+        public void StopRecordAudio(int type)
862
         {
865
         {
863
             try
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
             catch (Exception ex)
897
             catch (Exception ex)
878
         }
901
         }
879
 
902
 
880
 
903
 
881
-        //录制扬声器的声音
904
+        /// <summary>
905
+        /// 录制扬声器的声音
906
+        /// </summary>
882
         private WasapiLoopbackCapture capture = null; //new WasapiLoopbackCapture();
907
         private WasapiLoopbackCapture capture = null; //new WasapiLoopbackCapture();
883
 
908
 
884
         /// <summary>
909
         /// <summary>

+ 60
- 7
XHWK.WKTool/ScreenRecordingToolbarWindow.xaml.cs View File

107
             btnBlackPenOne.IsEnabled = false;//蓝笔不可点击
107
             btnBlackPenOne.IsEnabled = false;//蓝笔不可点击
108
             imgBlackPenTwo.Source = new BitmapImage(new Uri("pack://application:,,,/Images/31.png"));
108
             imgBlackPenTwo.Source = new BitmapImage(new Uri("pack://application:,,,/Images/31.png"));
109
             btnBlackPenTwo.IsEnabled = false;//红笔不可点击
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
             txbTime.Visibility = Visibility.Hidden;//时间不显示
112
             txbTime.Visibility = Visibility.Hidden;//时间不显示
113
             if (t == null)
113
             if (t == null)
114
             {
114
             {
232
         {
232
         {
233
             //FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temp/");
233
             //FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temp/");
234
             FileToolsCommon.CreateDirectory(APP.WKData.WkPath);
234
             FileToolsCommon.CreateDirectory(APP.WKData.WkPath);
235
-            FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "tempsr/");
235
+            FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temprs/");
236
             VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录屏." + ((Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType"))).ToString();
236
             VideoSavePathName = APP.WKData.WkPath + APP.WKData.WkName + "_录屏." + ((Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType"))).ToString();
237
             int num = 1;
237
             int num = 1;
238
             while (FileToolsCommon.IsExistFile(VideoSavePathName))
238
             while (FileToolsCommon.IsExistFile(VideoSavePathName))
267
                     //扬声器
267
                     //扬声器
268
                     if (APP.FFmpeg.StartRecordSpeakerAudio(audioSpeakerPath))
268
                     if (APP.FFmpeg.StartRecordSpeakerAudio(audioSpeakerPath))
269
                     {
269
                     {
270
-                        APP.FFmpeg.StopRecordAudio();
270
+                        APP.FFmpeg.StopRecordAudio(2);
271
                         //Thread.Sleep(500);
271
                         //Thread.Sleep(500);
272
                         //麦克风
272
                         //麦克风
273
                         if (APP.FFmpeg.StartRecordAudio(audioMicrophonePath))
273
                         if (APP.FFmpeg.StartRecordAudio(audioMicrophonePath))
282
                                 return;
282
                                 return;
283
                             }
283
                             }
284
                         }
284
                         }
285
-                        APP.FFmpeg.StopRecordAudio();
285
+                        APP.FFmpeg.StopRecordAudio(1);
286
                     }
286
                     }
287
                     else
287
                     else
288
                     {
288
                     {
341
                 btnBlackPenOne.IsEnabled = true;//蓝笔可点击
341
                 btnBlackPenOne.IsEnabled = true;//蓝笔可点击
342
                 imgBlackPenTwo.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar28.png"));
342
                 imgBlackPenTwo.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar28.png"));
343
                 btnBlackPenTwo.IsEnabled = true;//红笔可点击
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
                 txbTime.Visibility = Visibility.Visible;//时间显示
346
                 txbTime.Visibility = Visibility.Visible;//时间显示
347
                 try
347
                 try
348
                 {
348
                 {
352
                         {
352
                         {
353
                             Thread.Sleep(1500);
353
                             Thread.Sleep(1500);
354
                         }
354
                         }
355
+                        if(APP.FFmpeg.myProcess!=null)
356
+                        {
357
+                            Thread.Sleep(100);
358
+                        }
355
                         APP.FFmpeg.StartRecordingVideo(VideoSavePathName);
359
                         APP.FFmpeg.StartRecordingVideo(VideoSavePathName);
356
 
360
 
357
                         Thread.Sleep(1000);
361
                         Thread.Sleep(1000);
876
         /// <param name="e"></param>
880
         /// <param name="e"></param>
877
         private void BtnReturn_Click(object sender, RoutedEventArgs e)
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
             if (APP.W_XHMicroLessonSystemWindow == null)
907
             if (APP.W_XHMicroLessonSystemWindow == null)
880
             {
908
             {
881
                 APP.W_XHMicroLessonSystemWindow = new XHMicroLessonSystemWindow();
909
                 APP.W_XHMicroLessonSystemWindow = new XHMicroLessonSystemWindow();
882
             }
910
             }
883
             APP.W_XHMicroLessonSystemWindow.Show();
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
             Hide();
937
             Hide();
885
         }
938
         }
886
     }
939
     }

+ 5
- 2
XHWK.WKTool/XHMicroLessonSystemWindow.xaml.cs View File

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

Loading…
Cancel
Save