|
@@ -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(() =>
|