Pārlūkot izejas kodu

zhao:增加扬声器检测

tags/录制修改前
耀 pirms 4 gadiem
vecāks
revīzija
d61bb0d576

+ 213
- 53
Common/system/FFMpeg.cs Parādīt failu

@@ -23,6 +23,14 @@ namespace Common.system
23 23
         /// </summary>
24 24
         string LogPath = "";
25 25
         /// <summary>
26
+        /// 是否可以录制扬声器
27
+        /// </summary>
28
+        bool IsRecordSpeaker = true;
29
+        /// <summary>
30
+        /// 是否可以录制麦克风
31
+        /// </summary>
32
+        bool IsRecordMicrophone = true;
33
+        /// <summary>
26 34
         /// 录制屏幕
27 35
         /// </summary>
28 36
         /// <param name="FilePath">文件存储路径</param>
@@ -45,56 +53,84 @@ namespace Common.system
45 53
             myProcess = new Process();
46 54
             LogPath = CreateffmpegLog();
47 55
             string MicrophoneName = null;
48
-            string audioTestPath = FileToolsCommon.GetFileAbsolutePath("ado.m");
56
+            #region 检测麦克风扬声器
57
+            string audioSpeakerPath = FileToolsCommon.GetFileAbsolutePath("adoS.m");
58
+            string audioMicrophonePath = FileToolsCommon.GetFileAbsolutePath("adoM.m");
49 59
             try
50 60
             {
51
-                FileToolsCommon.DeleteFile(audioTestPath);
61
+                FileToolsCommon.DeleteFile(audioSpeakerPath);
62
+                FileToolsCommon.DeleteFile(audioMicrophonePath);
52 63
             }
53 64
             catch (Exception)
54 65
             {
55 66
 
56 67
             }
57
-            if (StartRecordAudio(audioTestPath))
68
+            if(StartRecordSpeakerAudio(audioSpeakerPath))
58 69
             {
59
-                MicrophoneName = GetMicrophone();
70
+                IsRecordSpeaker = true;
71
+            }
72
+            else
73
+            {
74
+                //无法录制扬声器音频
75
+                IsRecordSpeaker = false;
60 76
             }
61 77
             StopRecordAudio();
78
+            Thread.Sleep(500);
79
+            if (StartRecordAudio(audioMicrophonePath))
80
+            {
81
+                IsRecordMicrophone = true;
82
+            }
83
+            else
84
+            {
85
+                //无法录制扬声器
86
+                IsRecordMicrophone = false;
87
+            }
88
+            StopRecordAudio();
89
+            #endregion
62 90
             myProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath(@"/ffmpeg/bin/ffmpeg.exe");   //ffmpeg.exe的绝对路径
91
+            string SpeakerStr = "";
92
+            string MicrophoneStr = "";
93
+            if (IsRecordSpeaker)
94
+            {
95
+                SpeakerStr = "-f dshow -i audio=\"virtual-audio-capturer\" ";
96
+            }
97
+            if(IsRecordMicrophone)
98
+            {
99
+                MicrophoneName = GetMicrophone();
100
+                if (!string.IsNullOrWhiteSpace(MicrophoneName))
101
+                {
102
+                    MicrophoneStr = "-f dshow -i audio=\"" + MicrophoneName + "\" -filter_complex amix=inputs=2:duration=first:dropout_transition=2 ";
103
+                }
104
+            }
63 105
             switch (Extension.ToUpper())
64 106
             {
65 107
                 case ".MP4":
66
-                    if (string.IsNullOrWhiteSpace(MicrophoneName))
67
-                    {
68
-                        myProcess.StartInfo.Arguments = "-f dshow -i video=\"screen-capture-recorder\" -f dshow -i audio=\"virtual-audio-capturer\" -vcodec libx264 -acodec libmp3lame -r 15 -crf 22 -f avi " + PathName;  //ffmpeg的参数
69
-                    }
70
-                    else
71
-                    {
72
-                        myProcess.StartInfo.Arguments = "-f dshow -i audio=\"virtual-audio-capturer\" -f dshow -i audio=\"" +
73
-                            MicrophoneName + "\" -filter_complex amix=inputs=2:duration=first:dropout_transition=2 -f dshow -i video=\"screen-capture-recorder\" -pix_fmt yuv420p -vcodec h264 -preset:v ultrafast -tune:v zerolatency -acodec aac -ar 44100 -ac 2 " + PathName;  //ffmpeg的参数
74
-                    }
108
+                    myProcess.StartInfo.Arguments = SpeakerStr + MicrophoneStr + " -f dshow -i video=\"screen-capture-recorder\" -pix_fmt yuv420p -vcodec libx264 -preset:v ultrafast -tune:v zerolatency -acodec aac " + PathName;
109
+                    //if (string.IsNullOrWhiteSpace(MicrophoneName))
110
+                    //{
111
+                    //    myProcess.StartInfo.Arguments = "-f dshow -i video=\"screen-capture-recorder\" -f dshow -i audio=\"virtual-audio-capturer\" -vcodec libx264 -acodec libmp3lame -r 15 -crf 22 " + PathName;  //ffmpeg的参数
112
+                    //}
113
+                    //else
114
+                    //{
115
+                    //    myProcess.StartInfo.Arguments = "-f dshow -i audio=\"virtual-audio-capturer\" -f dshow -i audio=\"" +
116
+                    //        MicrophoneName + "\" -filter_complex amix=inputs=2:duration=first:dropout_transition=2 -f dshow -i video=\"screen-capture-recorder\" -pix_fmt yuv420p -vcodec h264 -preset:v ultrafast -tune:v zerolatency -acodec aac -ar 44100 -ac 2 " + PathName;  //ffmpeg的参数
117
+                    //}
75 118
                     break;
76 119
                 case ".AVI":
77 120
                 case ".FLV":
78
-                    if (string.IsNullOrWhiteSpace(MicrophoneName))
79
-                    {
80
-                        myProcess.StartInfo.Arguments = "-f dshow -i video=\"screen-capture-recorder\" -f dshow -i audio=\"virtual-audio-capturer\" -vcodec libx264 -acodec libmp3lame -r 15 -crf 22 -f " + Extension.ToLower() + " " + PathName;  //ffmpeg的参数
81
-                    }
82
-                    else
83
-                    {
84
-                        myProcess.StartInfo.Arguments = "-f dshow -i audio=\"virtual-audio-capturer\" -f dshow -i audio=\"" +
85
-                            MicrophoneName + "\" -filter_complex amix=inputs=2:duration=first:dropout_transition=2 -f dshow -i video=\"screen-capture-recorder\" -pix_fmt yuv420p -vcodec h264 -preset:v ultrafast -tune:v zerolatency -acodec aac -ar 44100 -ac 2 -f " + Extension.ToLower() + " " + PathName;  //ffmpeg的参数
86
-                    }
121
+                    myProcess.StartInfo.Arguments = SpeakerStr + MicrophoneStr + " -f dshow -i video=\"screen-capture-recorder\" -pix_fmt yuv420p -vcodec libx264 -preset:v ultrafast -tune:v zerolatency -acodec aac -f " + Extension.ToLower().Replace(".","") + " " + PathName;
122
+                    //if (string.IsNullOrWhiteSpace(MicrophoneName))
123
+                    //{
124
+                    //    myProcess.StartInfo.Arguments = "-f dshow -i video=\"screen-capture-recorder\" -f dshow -i audio=\"virtual-audio-capturer\" -vcodec libx264 -acodec libmp3lame -r 15 -crf 22 -f " + Extension.ToLower() + " " + PathName;  //ffmpeg的参数
125
+                    //}
126
+                    //else
127
+                    //{
128
+                    //    myProcess.StartInfo.Arguments = "-f dshow -i audio=\"virtual-audio-capturer\" -f dshow -i audio=\"" +
129
+                    //        MicrophoneName + "\" -filter_complex amix=inputs=2:duration=first:dropout_transition=2 -f dshow -i video=\"screen-capture-recorder\" -pix_fmt yuv420p -vcodec h264 -preset:v ultrafast -tune:v zerolatency -acodec aac -ar 44100 -ac 2 -f " + Extension.ToLower() + " " + PathName;  //ffmpeg的参数
130
+                    //}
87 131
                     break;
88 132
                 default:
89
-                    if (string.IsNullOrWhiteSpace(MicrophoneName))
90
-                    {
91
-                        myProcess.StartInfo.Arguments = "-f dshow -i video=\"screen-capture-recorder\" -f dshow -i audio=\"virtual-audio-capturer\" -vcodec libx264 -acodec libmp3lame -r 15 -crf 22 -f avi " + PathName;  //ffmpeg的参数
92
-                    }
93
-                    else
94
-                    {
95
-                        myProcess.StartInfo.Arguments = "-f dshow -i audio=\"virtual-audio-capturer\" -f dshow -i audio=\"" +
96
-                            MicrophoneName + "\" -filter_complex amix=inputs=2:duration=first:dropout_transition=2 -f dshow -i video=\"screen-capture-recorder\" -pix_fmt yuv420p -vcodec h264 -preset:v ultrafast -tune:v zerolatency -acodec aac -ar 44100 -ac 2 " + PathName;  //ffmpeg的参数
97
-                    }
133
+                    myProcess.StartInfo.Arguments = SpeakerStr + MicrophoneStr + " -f dshow -i video=\"screen-capture-recorder\" -pix_fmt yuv420p -vcodec libx264 -preset:v ultrafast -tune:v zerolatency -acodec aac " + PathName;
98 134
                     break;
99 135
             }
100 136
             myProcess.StartInfo.UseShellExecute = false;           //不使用操作系统外壳程序启动
@@ -110,7 +146,7 @@ namespace Common.system
110 146
         /// 录制音频
111 147
         /// </summary>
112 148
         /// <param name="Mp3Path">MP3音频位置</param>
113
-        public void StartRecordingAudio(string Mp3Path)
149
+        public bool StartRecordingAudio(string Mp3Path)
114 150
         {
115 151
             while (myProcess != null)
116 152
             {
@@ -125,33 +161,67 @@ namespace Common.system
125 161
             {
126 162
                 KillProcess.Kill();
127 163
             }
128
-            myProcess = new Process();
129
-            LogPath = CreateffmpegLog();
130
-            this.myProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath(@"/ffmpeg/bin/ffmpeg.exe");   //ffmpeg.exe的绝对路径
131 164
             string MicrophoneName = null;
132
-            string audioTestPath = FileToolsCommon.GetFileAbsolutePath("ado.m");
165
+            #region 检测麦克风扬声器
166
+            string audioSpeakerPath = FileToolsCommon.GetFileAbsolutePath("adoS.m");
167
+            string audioMicrophonePath = FileToolsCommon.GetFileAbsolutePath("adoM.m");
133 168
             try
134 169
             {
135
-                FileToolsCommon.DeleteFile(audioTestPath);
170
+                FileToolsCommon.DeleteFile(audioSpeakerPath);
171
+                FileToolsCommon.DeleteFile(audioMicrophonePath);
136 172
             }
137 173
             catch (Exception)
138 174
             {
139 175
 
140 176
             }
141
-            if (StartRecordAudio(audioTestPath))
177
+            if (StartRecordSpeakerAudio(audioSpeakerPath))
142 178
             {
143
-                MicrophoneName = GetMicrophone();
179
+                IsRecordSpeaker = true;
180
+            }
181
+            else
182
+            {
183
+                //无法录制扬声器音频
184
+                IsRecordSpeaker = false;
144 185
             }
145 186
             StopRecordAudio();
146
-            if (string.IsNullOrWhiteSpace(MicrophoneName))
187
+            Thread.Sleep(500);
188
+            if (StartRecordAudio(audioMicrophonePath))
147 189
             {
148
-                myProcess.StartInfo.Arguments = "-f dshow -i audio=\"virtual-audio-capturer\" " + PathName;
190
+                IsRecordMicrophone = true;
191
+                MicrophoneName = GetMicrophone();
149 192
             }
150 193
             else
194
+            {
195
+                //无法录制扬声器
196
+                IsRecordMicrophone = false;
197
+            }
198
+            StopRecordAudio();
199
+            if (!IsRecordSpeaker && !IsRecordMicrophone)
200
+            {
201
+                return false;
202
+            }
203
+            #endregion
204
+            myProcess = new Process();
205
+            LogPath = CreateffmpegLog();
206
+            this.myProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath(@"/ffmpeg/bin/ffmpeg.exe");   //ffmpeg.exe的绝对路径
207
+            if(IsRecordSpeaker && IsRecordMicrophone)
151 208
             {
152 209
                 myProcess.StartInfo.Arguments = "-f dshow -i audio=\"virtual-audio-capturer\"  -f dshow -i audio=\"" +
153 210
                         MicrophoneName + "\" -filter_complex amix=inputs=2:duration=first:dropout_transition=2 " + PathName;
154 211
             }
212
+            else if(IsRecordSpeaker)
213
+            {
214
+                myProcess.StartInfo.Arguments = "-f dshow -i audio=\"virtual-audio-capturer\" " + PathName;
215
+            }
216
+            else if(IsRecordMicrophone)
217
+            {
218
+                //录制麦克风
219
+                if (!string.IsNullOrWhiteSpace(MicrophoneName))
220
+                {
221
+                    myProcess.StartInfo.Arguments = "-f dshow -i audio=\"" +
222
+                        MicrophoneName + "\" -filter_complex amix=inputs=2:duration=first:dropout_transition=2 " + PathName;
223
+                }
224
+            }
155 225
             myProcess.StartInfo.UseShellExecute = false;           //不使用操作系统外壳程序启动
156 226
             myProcess.StartInfo.RedirectStandardError = true;      //重定向标准错误输出
157 227
             myProcess.StartInfo.CreateNoWindow = true;             //不显示程序窗口
@@ -160,6 +230,7 @@ namespace Common.system
160 230
             myProcess.ErrorDataReceived += new DataReceivedEventHandler(Output);
161 231
             myProcess.Start();                //启动线程
162 232
             myProcess.BeginErrorReadLine();   //开始异步读取
233
+            return true;
163 234
         }
164 235
 
165 236
         /// <summary>
@@ -252,31 +323,41 @@ namespace Common.system
252 323
             }
253 324
             myProcess = new Process();
254 325
             LogPath = CreateffmpegLog();
326
+            string mp3Str = "";
327
+            #region 判断音频是否存在
328
+            if (!string.IsNullOrWhiteSpace(Mp3Path))
329
+            {
330
+                if (FileToolsCommon.IsExistFile(Mp3Path))
331
+                {
332
+                    mp3Str = "-i " + Mp3Path;
333
+                }
334
+            }
335
+            #endregion
255 336
             this.myProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath(@"/ffmpeg/bin/ffmpeg.exe");   //ffmpeg.exe的绝对路径
256 337
             switch (Extension.ToUpper())
257 338
             {
258 339
                 case ".MP4":
259 340
                     myProcess.StartInfo.Arguments = @"-y -r " + Frequency + " -i " +
260
-                        ImageListPath + @"%d.png -i " +
261
-                        Mp3Path + @" -s " + VideoWidth + "x" + VideoHeight + " -vcodec mpeg4 " +
341
+                        ImageListPath + @"%d.png " +
342
+                        mp3Str + @" -s " + VideoWidth + "x" + VideoHeight + " -vcodec mpeg4 " +
262 343
                         VideoSavePath;
263 344
                     break;
264 345
                 case ".AVI":
265 346
                     myProcess.StartInfo.Arguments = @"-y -r " + Frequency + " -i " +
266
-                        ImageListPath + @"%d.png -i " +
267
-                        Mp3Path + @" -s " + VideoWidth + "x" + VideoHeight + " -f AVI " +
347
+                        ImageListPath + @"%d.png " +
348
+                        mp3Str + @" -s " + VideoWidth + "x" + VideoHeight + " -f AVI " +
268 349
                         VideoSavePath;
269 350
                     break;
270 351
                 case ".FLV":
271 352
                     myProcess.StartInfo.Arguments = @"-y -r " + Frequency + " -i " +
272
-                        ImageListPath + @"%d.png -i " +
273
-                        Mp3Path + @" -s " + VideoWidth + "x" + VideoHeight + " -f FLV " +
353
+                        ImageListPath + @"%d.png " +
354
+                        mp3Str + @" -s " + VideoWidth + "x" + VideoHeight + " -f FLV " +
274 355
                         VideoSavePath;
275 356
                     break;
276 357
                 default:
277 358
                     myProcess.StartInfo.Arguments = @"-y -r " + Frequency + " -i " +
278
-                        ImageListPath + @"%d.png -i " +
279
-                        Mp3Path + @" -s " + VideoWidth + "x" + VideoHeight + " -vcodec mpeg4 " +
359
+                        ImageListPath + @"%d.png " +
360
+                        mp3Str + @" -s " + VideoWidth + "x" + VideoHeight + " -vcodec mpeg4 " +
280 361
                         VideoSavePath;
281 362
                     break;
282 363
             }
@@ -339,12 +420,29 @@ namespace Common.system
339 420
             //路径
340 421
             string FilePath = (string)FilePathobj;
341 422
             string Path = FileToolsCommon.GetDirectoryName(FilePath);
342
-            string Extension = FileToolsCommon.GetIOExtension(FilePath);//扩展名
423
+            //扩展名
424
+            string Extension = FileToolsCommon.GetIOExtension(FilePath);
343 425
             //Process[] KillProcessArray = Process.GetProcessesByName("ffmpeg");
344 426
             //foreach (var KillProcess in KillProcessArray)
345 427
             //{
346 428
             //    KillProcess.Kill();
347 429
             //}
430
+            #region 判断文件是否存在
431
+            if (Extension.ToUpper() == ".MP3")
432
+            {
433
+                if (!FileToolsCommon.IsExistFile(Path + "temp/filelist.d"))
434
+                {
435
+                    return;
436
+                }
437
+            }
438
+            else
439
+            {
440
+                if (!FileToolsCommon.IsExistFile(Path + "temprs/filelist.d"))
441
+                {
442
+                    return;
443
+                }
444
+            }
445
+            #endregion
348 446
             myProcess = new Process();
349 447
             LogPath = CreateffmpegLog();
350 448
             this.myProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath(@"/ffmpeg/bin/ffmpeg.exe");   //ffmpeg.exe的绝对路径
@@ -633,7 +731,7 @@ namespace Common.system
633 731
         //录制麦克风的声音
634 732
         WaveInEvent waveIn = null; //new WaveInEvent();
635 733
         /// <summary>
636
-        /// 开始录制
734
+        /// 开始录制麦克风
637 735
         /// </summary>
638 736
         public bool StartRecordAudio(string audioFile)
639 737
         {
@@ -654,6 +752,15 @@ namespace Common.system
654 752
                     writer.Dispose();
655 753
                     writer = null;
656 754
                     waveIn.Dispose();
755
+                    waveIn = null;
756
+                    try
757
+                    {
758
+                        FileToolsCommon.DeleteFile(audioFile);
759
+                    }
760
+                    catch (Exception)
761
+                    {
762
+
763
+                    }
657 764
                 };
658 765
                 waveIn.StartRecording();
659 766
                 return true;
@@ -665,16 +772,69 @@ namespace Common.system
665 772
             }
666 773
         }
667 774
 
668
-        //结束录制
775
+        /// <summary>
776
+        /// 结束录制音频
777
+        /// </summary>
669 778
         public void StopRecordAudio()
670 779
         {
671 780
             try
672 781
             {
673
-                waveIn.StopRecording();
782
+                if (waveIn != null)
783
+                {
784
+                    waveIn.StopRecording(); 
785
+                }
786
+                if (capture != null)
787
+                {
788
+                    capture.StopRecording();
789
+                }
790
+            }
791
+            catch (Exception ex)
792
+            {
793
+                LogHelper.WriteErrLog("【麦克风】麦克风不可用:" + ex.Message, ex);
794
+            }
795
+        }
796
+
797
+
798
+        //录制扬声器的声音
799
+        WasapiLoopbackCapture capture = null; //new WasapiLoopbackCapture();
800
+
801
+        /// <summary>
802
+        /// 开始录制扬声器
803
+        /// </summary>
804
+        public bool StartRecordSpeakerAudio(string audioFile)
805
+        {
806
+            try
807
+            {
808
+                capture = new WasapiLoopbackCapture();
809
+                //生成音频文件的对象
810
+                WaveFileWriter writer = new WaveFileWriter(audioFile, capture.WaveFormat);
811
+                capture.DataAvailable += (s, a) =>
812
+                {
813
+                    writer.Write(a.Buffer, 0, a.BytesRecorded);
814
+                };
815
+                //结束录音
816
+                capture.RecordingStopped += (s, a) =>
817
+                {
818
+                    writer.Dispose();
819
+                    writer = null;
820
+                    capture.Dispose();
821
+                    capture = null;
822
+                    try
823
+                    {
824
+                        FileToolsCommon.DeleteFile(audioFile);
825
+                    }
826
+                    catch (Exception)
827
+                    {
828
+
829
+                    }
830
+                };
831
+                capture.StartRecording();
832
+                return true;
674 833
             }
675 834
             catch (Exception ex)
676 835
             {
677 836
                 LogHelper.WriteErrLog("【麦克风】麦克风不可用:" + ex.Message, ex);
837
+                return false;
678 838
             }
679 839
         }
680 840
     }

+ 43
- 0
XHWK.WKTool/ScreenRecordingToolbarWindow.xaml.cs Parādīt failu

@@ -218,6 +218,49 @@ namespace XHWK.WKTool
218 218
             {
219 219
                 if (IsFirstRS)
220 220
                 {
221
+                    #region 检测麦克风扬声器是否可用
222
+                    string audioSpeakerPath = FileToolsCommon.GetFileAbsolutePath("adoS.m");
223
+                    string audioMicrophonePath = FileToolsCommon.GetFileAbsolutePath("adoM.m");
224
+                    try
225
+                    {
226
+                        FileToolsCommon.DeleteFile(audioSpeakerPath);
227
+                        FileToolsCommon.DeleteFile(audioMicrophonePath);
228
+                    }
229
+                    catch (Exception)
230
+                    {
231
+
232
+                    }
233
+                    //扬声器
234
+                    if (APP.FFmpeg.StartRecordSpeakerAudio(audioSpeakerPath))
235
+                    {
236
+                        APP.FFmpeg.StopRecordAudio();
237
+                        //Thread.Sleep(500);
238
+                        //麦克风
239
+                        if (APP.FFmpeg.StartRecordAudio(audioMicrophonePath))
240
+                        {
241
+                        }
242
+                        else
243
+                        {
244
+                            //无法录制麦克风
245
+                            MessageBoxResult Res = MessageWindow.Show("当前电脑无法录制麦克风,是否继续?", "消息提示", MessageBoxButton.OKCancel);
246
+                            if (Res == MessageBoxResult.Cancel)
247
+                            {
248
+                                return;
249
+                            }
250
+                        }
251
+                        APP.FFmpeg.StopRecordAudio();
252
+                    }
253
+                    else
254
+                    {
255
+                        //无法录制扬声器音频
256
+                        MessageBoxResult Res = MessageWindow.Show("当前电脑无法录制音频,是否继续?", "消息提示", MessageBoxButton.OKCancel);
257
+                        if (Res == MessageBoxResult.Cancel)
258
+                        {
259
+                            return;
260
+                        }
261
+                    }
262
+                    #endregion
263
+
221 264
                     VideoInfo = new Model_Video();
222 265
                     VideoInfo.VideoType = (Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType"));
223 266
                     VideoInfo.WkType = Enum_WKVidetype.RecordingScreen;

+ 83
- 14
XHWK.WKTool/XHMicroLessonSystemWindow.xaml.cs Parādīt failu

@@ -1248,6 +1248,10 @@ namespace XHWK.WKTool
1248 1248
         /// 是否开始截图计数
1249 1249
         /// </summary>
1250 1250
         bool IsStartCount = false;
1251
+        /// <summary>
1252
+        /// 是否录制了音频
1253
+        /// </summary>
1254
+        bool IsRecordAudio = false;
1251 1255
         #endregion
1252 1256
         /// <summary>
1253 1257
         /// 录制窗口内容
@@ -1275,6 +1279,7 @@ namespace XHWK.WKTool
1275 1279
             {
1276 1280
                 HideAngleBorder();
1277 1281
             }
1282
+
1278 1283
             //btnStop.IsEnabled = true;//停止录制按钮可点击
1279 1284
             StartRecord();
1280 1285
         }
@@ -1305,6 +1310,49 @@ namespace XHWK.WKTool
1305 1310
             {
1306 1311
                 if (IsFirstR)//是否第一次录制  初始化录制
1307 1312
                 {
1313
+                    #region 检测麦克风扬声器是否可用
1314
+                    string audioSpeakerPath = FileToolsCommon.GetFileAbsolutePath("adoS.m");
1315
+                    string audioMicrophonePath = FileToolsCommon.GetFileAbsolutePath("adoM.m");
1316
+                    try
1317
+                    {
1318
+                        FileToolsCommon.DeleteFile(audioSpeakerPath);
1319
+                        FileToolsCommon.DeleteFile(audioMicrophonePath);
1320
+                    }
1321
+                    catch (Exception)
1322
+                    {
1323
+
1324
+                    }
1325
+                    //扬声器
1326
+                    if (APP.FFmpeg.StartRecordSpeakerAudio(audioSpeakerPath))
1327
+                    {
1328
+                        APP.FFmpeg.StopRecordAudio();
1329
+                        //Thread.Sleep(500);
1330
+                        //麦克风
1331
+                        if (APP.FFmpeg.StartRecordAudio(audioMicrophonePath))
1332
+                        {
1333
+                        }
1334
+                        else
1335
+                        {
1336
+                            //无法录制麦克风
1337
+                            MessageBoxResult Res = MessageWindow.Show("当前电脑无法录制麦克风,是否继续?", "消息提示", MessageBoxButton.OKCancel);
1338
+                            if (Res == MessageBoxResult.Cancel)
1339
+                            {
1340
+                                return;
1341
+                            }
1342
+                        }
1343
+                        APP.FFmpeg.StopRecordAudio();
1344
+                    }
1345
+                    else
1346
+                    {
1347
+                        //无法录制扬声器音频
1348
+                        MessageBoxResult Res = MessageWindow.Show("当前电脑无法录制音频,是否继续?", "消息提示", MessageBoxButton.OKCancel);
1349
+                        if (Res == MessageBoxResult.Cancel)
1350
+                        {
1351
+                            return;
1352
+                        }
1353
+                    }
1354
+                    #endregion
1355
+
1308 1356
                     #region 计时器初始化
1309 1357
                     if (t == null)
1310 1358
                     {
@@ -1438,7 +1486,7 @@ namespace XHWK.WKTool
1438 1486
                     new Thread(new ThreadStart(new Action(() =>
1439 1487
                     {
1440 1488
                         Thread.Sleep(1000);
1441
-                        APP.FFmpeg.StartRecordingAudio(AudioPathName);
1489
+                        IsRecordAudio = APP.FFmpeg.StartRecordingAudio(AudioPathName);
1442 1490
                         Thread.Sleep(1000);
1443 1491
                         Dispatcher.Invoke(() =>
1444 1492
                         {
@@ -1606,22 +1654,30 @@ namespace XHWK.WKTool
1606 1654
                             IsStartCount = false;
1607 1655
                             timer.Stop();
1608 1656
                         });
1609
-                    //}))).Start();
1610
-                    //new Thread(new ThreadStart(new Action(() =>
1611
-                    //{
1657
+                        //}))).Start();
1658
+                        //new Thread(new ThreadStart(new Action(() =>
1659
+                        //{
1612 1660
                         //判断音频是否存在 判断音频临时文件夹是否存在
1613
-                        if (!FileToolsCommon.IsExistFile(AudioPathName))
1661
+                        if (IsRecordAudio)
1614 1662
                         {
1615
-                            Thread.Sleep(100);
1663
+                            if (!FileToolsCommon.IsExistFile(AudioPathName))
1664
+                            {
1665
+                                Thread.Sleep(100);
1666
+                            }
1667
+                            if (FileToolsCommon.IsExistDirectory(FileToolsCommon.GetDirectoryName(AudioPathName) + "temp/"))
1668
+                            {
1669
+                                Thread.Sleep(100);
1670
+                            }
1616 1671
                         }
1617
-                        if (FileToolsCommon.IsExistDirectory(FileToolsCommon.GetDirectoryName(AudioPathName) + "temp/"))
1672
+                        else
1618 1673
                         {
1619
-                            Thread.Sleep(100);
1674
+                            //没有录制音频
1675
+                            AudioPathName = null;
1620 1676
                         }
1621 1677
                         APP.FFmpeg.SynthesisVideo(ImgPath, AudioPathName, VideoSavePathName, 5, gridActWidth, gridActHeight);
1622
-                    //}))).Start();
1623
-                    //new Thread(new ThreadStart(new Action(() =>
1624
-                    //{
1678
+                        //}))).Start();
1679
+                        //new Thread(new ThreadStart(new Action(() =>
1680
+                        //{
1625 1681
                         while (!FileToolsCommon.IsExistFile(VideoSavePathName))
1626 1682
                         {
1627 1683
                             Thread.Sleep(100);
@@ -3328,9 +3384,22 @@ namespace XHWK.WKTool
3328 3384
         {
3329 3385
             try
3330 3386
             {
3331
-            Thumb thu = (Thumb)sender;
3332
-            Canvas.SetLeft(thu, Canvas.GetLeft(thu) + e.HorizontalChange);
3333
-            Canvas.SetTop(thu, Canvas.GetTop(thu) + e.VerticalChange);
3387
+                Thumb thu = (Thumb)sender;
3388
+                #region 判断是否超出 暂无
3389
+                double plul = Canvas.GetLeft(RectLeftUp);
3390
+                double plut = Canvas.GetTop(RectLeftUp);
3391
+                double prdl = Canvas.GetLeft(RectRightDown);
3392
+                double prdt = Canvas.GetTop(RectRightDown);
3393
+                if (prdl - plul > 50)
3394
+                {
3395
+                }
3396
+                if (prdt - plut > 50)
3397
+                {
3398
+                }
3399
+                #endregion
3400
+                
3401
+                    Canvas.SetLeft(thu, Canvas.GetLeft(thu) + e.HorizontalChange);
3402
+                    Canvas.SetTop(thu, Canvas.GetTop(thu) + e.VerticalChange);
3334 3403
                 switch (thu.Name)
3335 3404
                 {
3336 3405
                     case "RectLeftUp":

Notiek ielāde…
Atcelt
Saglabāt