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

Merge remote-tracking branch 'origin/zyy' into zhangxueyang

tags/录制修改前
zhangxueyang преди 4 години
родител
ревизия
fae26e576d

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

@@ -17,7 +17,7 @@ namespace Common.system
17 17
     /// </summary>
18 18
     public class FFMpeg
19 19
     {
20
-        Process myProcess = null;
20
+        public Process myProcess = null;
21 21
         /// <summary>
22 22
         /// ffmpeg输出日志文件地址  每个文件2MB左右
23 23
         /// </summary>
@@ -28,13 +28,16 @@ namespace Common.system
28 28
         /// <param name="FilePath">文件存储路径</param>
29 29
         public void StartRecordingVideo(string FilePath)
30 30
         {
31
+            while (myProcess != null)
32
+            {
33
+                Thread.Sleep(100);
34
+            }
31 35
             //路径
32
-            string Path = FileToolsCommon.GetDirectoryName(FilePath) + @"\";
36
+            string Path = FileToolsCommon.GetDirectoryName(FilePath);
33 37
             string Extension = FileToolsCommon.GetIOExtension(FilePath);//扩展名
34 38
             //文件保存路径
35 39
             string PathName = GetFilePathName(FilePath);
36 40
             Process[] KillProcessArray = Process.GetProcessesByName("ffmpeg");
37
-            Debug.WriteLine(KillProcessArray.Length.ToString());
38 41
             foreach (var KillProcess in KillProcessArray)
39 42
             {
40 43
                 KillProcess.Kill();
@@ -95,8 +98,13 @@ namespace Common.system
95 98
         /// <param name="Mp3Path">MP3音频位置</param>
96 99
         public void StartRecordingAudio(string Mp3Path)
97 100
         {
101
+            while (myProcess != null)
102
+            {
103
+                Thread.Sleep(100);
104
+            }
105
+            //文件保存路径
106
+            string PathName = GetFilePathName(Mp3Path);
98 107
             Process[] KillProcessArray = Process.GetProcessesByName("ffmpeg");
99
-            Debug.WriteLine(KillProcessArray.Length.ToString());
100 108
             foreach (var KillProcess in KillProcessArray)
101 109
             {
102 110
                 KillProcess.Kill();
@@ -107,12 +115,12 @@ namespace Common.system
107 115
             string MicrophoneName = GetMicrophone();
108 116
             if (string.IsNullOrWhiteSpace(MicrophoneName))
109 117
             {
110
-                myProcess.StartInfo.Arguments = "-f dshow -i audio=\"virtual-audio-capturer\" " + Mp3Path;
118
+                myProcess.StartInfo.Arguments = "-f dshow -i audio=\"virtual-audio-capturer\" " + PathName;
111 119
             }
112 120
             else
113 121
             {
114 122
                 myProcess.StartInfo.Arguments = "-f dshow -i audio=\"virtual-audio-capturer\"  -f dshow -i audio=\"" +
115
-                        MicrophoneName + "\" -filter_complex amix=inputs=2:duration=first:dropout_transition=2 " + Mp3Path;
123
+                        MicrophoneName + "\" -filter_complex amix=inputs=2:duration=first:dropout_transition=2 " + PathName;
116 124
             }
117 125
             myProcess.StartInfo.UseShellExecute = false;           //不使用操作系统外壳程序启动
118 126
             myProcess.StartInfo.RedirectStandardError = true;      //重定向标准错误输出
@@ -127,14 +135,29 @@ namespace Common.system
127 135
         /// <summary>
128 136
         /// 暂停录制
129 137
         /// </summary>
130
-        public void SuspendFFmpeg()
138
+        public bool SuspendFFmpeg()
131 139
         {
132
-            if (myProcess == null)
133
-                return;
134
-            myProcess.StandardInput.WriteLine("q");//在这个进程的控制台中模拟输入q,用于暂停录制
135
-            myProcess.Close();//关闭进程
136
-            myProcess.Dispose();//释放资源
140
+            if (myProcess != null)
141
+            {
142
+                myProcess.StandardInput.WriteLine("q");//在这个进程的控制台中模拟输入q,用于暂停录制
143
+                myProcess.Close();//关闭进程
144
+                myProcess.Dispose();//释放资源
145
+            }
146
+            #region 进程是否已经释放
147
+            bool IsRunning = true;
148
+            while (IsRunning)
149
+            {
150
+                IsRunning = false;
151
+                Process[] ProcessArray = Process.GetProcessesByName("ffmpeg");
152
+                foreach (var KillProcess in ProcessArray)
153
+                {
154
+                    IsRunning = true;
155
+                    Thread.Sleep(100);
156
+                }
157
+            }
158
+            #endregion
137 159
             myProcess = null;
160
+            return true;
138 161
             //myProcess.Kill();
139 162
         }
140 163
 
@@ -142,17 +165,32 @@ namespace Common.system
142 165
         /// 停止录制并合成文件
143 166
         /// </summary>
144 167
         /// <param name="FilePath">文件存储路径 必须与开始时的路径完全一致</param>
145
-        public void StopFFmpeg(string FilePath)
168
+        public bool StopFFmpeg(string FilePath)
146 169
         {
147 170
             //文件完整路径
148
-            if (myProcess == null)
149
-                return;
150
-            myProcess.StandardInput.WriteLine("q");//在这个进程的控制台中模拟输入q,用于暂停录制
151
-            myProcess.Close();//关闭进程
152
-            myProcess.Dispose();//释放资源
171
+            if (myProcess != null)
172
+            {
173
+                myProcess.StandardInput.WriteLine("q");//在这个进程的控制台中模拟输入q,用于暂停录制
174
+                myProcess.Close();//关闭进程
175
+                myProcess.Dispose();//释放资源
176
+            }
177
+            #region 进程是否已经释放
178
+            bool IsRunning = true;
179
+            while (IsRunning)
180
+            {
181
+                IsRunning = false;
182
+                Process[] ProcessArray = Process.GetProcessesByName("ffmpeg");
183
+                foreach (var KillProcess in ProcessArray)
184
+                {
185
+                    IsRunning = true;
186
+                    Thread.Sleep(100);
187
+                }
188
+            }
189
+            #endregion
153 190
             myProcess = null;
154 191
             Thread t1 = new Thread(MergeVideoOrAudio);
155 192
             t1.Start(FilePath);
193
+            return true;
156 194
             //文件合成
157 195
         }
158 196
 
@@ -167,14 +205,16 @@ namespace Common.system
167 205
         /// <param name="VideoHeight">视频高度</param>
168 206
         public void SynthesisVideo(string ImageListPath, string Mp3Path, string VideoSavePath, int Frequency, int VideoWidth, int VideoHeight)
169 207
         {
170
-            Thread thread = new Thread(delegate ()
208
+            new Thread(new ThreadStart(new Action(() =>
171 209
             {
172
-                //// 允许不同线程间的调用
173
-                //Control.CheckForIllegalCrossThreadCalls = false;
174 210
                 Thread.Sleep(500);
211
+                while (myProcess != null)
212
+                {
213
+                    Thread.Sleep(100);
214
+                }
175 215
                 string Extension = FileToolsCommon.GetIOExtension(VideoSavePath);//扩展名
176 216
                 Process[] KillProcessArray = Process.GetProcessesByName("ffmpeg");
177
-                Debug.WriteLine(KillProcessArray.Length.ToString());
217
+                //Debug.WriteLine(KillProcessArray.Length.ToString());
178 218
                 foreach (var KillProcess in KillProcessArray)
179 219
                 {
180 220
                     KillProcess.Kill();
@@ -220,23 +260,53 @@ namespace Common.system
220 260
                 myProcess.WaitForExit();           //阻塞等待进程结束
221 261
                 myProcess.Close();                 //关闭进程
222 262
                 myProcess.Dispose();               //释放资源
223
-                                                   //生成视频后删除图片保存列表
224
-                FileToolsCommon.DeleteDirectory(ImageListPath);
225
-            });
263
+                #region 进程是否已经释放
264
+                bool IsRunning = true;
265
+                while (IsRunning)
266
+                {
267
+                    IsRunning = false;
268
+                    Process[] ProcessArray = Process.GetProcessesByName("ffmpeg");
269
+                    foreach (var KillProcess in ProcessArray)
270
+                    {
271
+                        IsRunning = true;
272
+                        Thread.Sleep(100);
273
+                    }
274
+                }
275
+                #endregion
276
+                myProcess = null;
277
+                //生成视频后删除图片和音频保存列表
278
+                //FileToolsCommon.DeleteDirectory(ImageListPath);
279
+                //FileToolsCommon.DeleteDirectory(FileToolsCommon.GetDirectoryName(Mp3Path));
280
+
281
+                //Dispatcher.Invoke(() =>
282
+                //{
283
+                //});
284
+                //// 允许不同线程间的调用
285
+                //Control.CheckForIllegalCrossThreadCalls = false;
286
+            }))).Start();
226 287
         }
227 288
 
228 289
         /// <summary>
229 290
         /// 视频音频合成
230 291
         /// </summary>
231 292
         /// <param name="FilePath">存储路径</param>
232
-        void MergeVideoOrAudio(object FilePathobj)
293
+        public void MergeVideoOrAudio(object FilePathobj)
233 294
         {
234
-            Thread.Sleep(500);
295
+            //new Thread(new ThreadStart(new Action(() =>
296
+            //{
297
+            //Dispatcher.Invoke(() =>
298
+            //{
299
+            //});
300
+            //}))).Start();
301
+
302
+            while (myProcess != null)
303
+            {
304
+                Thread.Sleep(100);
305
+            }
235 306
             //路径
236 307
             string FilePath = (string)FilePathobj;
237
-            string Path = FileToolsCommon.GetDirectoryName(FilePath) + @"\";
308
+            string Path = FileToolsCommon.GetDirectoryName(FilePath);
238 309
             Process[] KillProcessArray = Process.GetProcessesByName("ffmpeg");
239
-            Debug.WriteLine(KillProcessArray.Length.ToString());
240 310
             foreach (var KillProcess in KillProcessArray)
241 311
             {
242 312
                 KillProcess.Kill();
@@ -256,6 +326,20 @@ namespace Common.system
256 326
             myProcess.WaitForExit();           //阻塞等待进程结束
257 327
             myProcess.Close();                 //关闭进程
258 328
             myProcess.Dispose();               //释放资源
329
+            #region 进程是否已经释放
330
+            bool IsRunning = true;
331
+            while (IsRunning)
332
+            {
333
+                IsRunning = false;
334
+                Process[] ProcessArray = Process.GetProcessesByName("ffmpeg");
335
+                foreach (var KillProcess in ProcessArray)
336
+                {
337
+                    IsRunning = true;
338
+                    Thread.Sleep(100);
339
+                }
340
+            }
341
+            #endregion
342
+            myProcess = null;
259 343
         }
260 344
 
261 345
         /// <summary>
@@ -266,7 +350,7 @@ namespace Common.system
266 350
         string GetFilePathName(string FilePath)
267 351
         {
268 352
             //路径
269
-            string Path = FileToolsCommon.GetDirectoryName(FilePath) + @"\";
353
+            string Path = FileToolsCommon.GetDirectoryName(FilePath);
270 354
             //Path.GetFileName(FilePath);//获取文件名
271 355
             string Extension = FileToolsCommon.GetIOExtension(FilePath);//扩展名
272 356
             string tempFilePath = Path + "temp/";
@@ -295,8 +379,11 @@ namespace Common.system
295 379
         /// <param name="ImagePath">图片地址</param>
296 380
         public void GenerateThumbnails(string VideoPath, string ImagePath)
297 381
         {
382
+            while (myProcess != null)
383
+            {
384
+                Thread.Sleep(100);
385
+            }
298 386
             Process[] KillProcessArray = Process.GetProcessesByName("ffmpeg");
299
-            Debug.WriteLine(KillProcessArray.Length.ToString());
300 387
             foreach (var KillProcess in KillProcessArray)
301 388
             {
302 389
                 KillProcess.Kill();
@@ -317,6 +404,20 @@ namespace Common.system
317 404
             myProcess.WaitForExit();           //阻塞等待进程结束
318 405
             myProcess.Close();                 //关闭进程
319 406
             myProcess.Dispose();               //释放资源
407
+            #region 进程是否已经释放
408
+            bool IsRunning = true;
409
+            while (IsRunning)
410
+            {
411
+                IsRunning = false;
412
+                Process[] ProcessArray = Process.GetProcessesByName("ffmpeg");
413
+                foreach (var KillProcess in ProcessArray)
414
+                {
415
+                    IsRunning = true;
416
+                    Thread.Sleep(100);
417
+                }
418
+            }
419
+            #endregion
420
+            myProcess = null;
320 421
         }
321 422
 
322 423
         /// <summary>

+ 2
- 1
Common/system/FileToolsCommon.cs Целия файл

@@ -70,6 +70,7 @@ namespace Common.system
70 70
             ErrMessage = "";
71 71
             try
72 72
             {
73
+                FilePathName = GetLegalPath(FilePathName);
73 74
                 FilePath = GetDirectoryName(FilePathName);
74 75
                 FileName = GetIOFileName(FilePathName);
75 76
             }
@@ -671,7 +672,7 @@ namespace Common.system
671 672
         /// <param name="filePath">文件的绝对路径</param>          
672 673
         public static string GetDirectoryName(string filePath)
673 674
         {
674
-            string DirectoryName = (System.IO.Path.GetDirectoryName(filePath) + "\\").Replace("\\", "/");
675
+            string DirectoryName = (System.IO.Path.GetDirectoryName(filePath+ "\\") ).Replace("\\", "/");
675 676
             return DirectoryName;
676 677
         }
677 678
         #endregion

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

@@ -85,44 +85,44 @@ namespace Common.system
85 85
         /// <returns></returns>
86 86
         public static BitmapImage GetScreenshot(Rectangle ScreenSize, string ImageSavePath, long level = -1)
87 87
         {
88
-            try
89
-            {
90
-                System.Drawing.Size bounds = PrimaryScreen.DESKTOP;
91
-                //if (string.IsNullOrEmpty(ImageSavePath))
92
-                //{
93
-                //    ImageSavePath = GetTempImagePath();//如果为空则指定临时存储路径
94
-                //}
95
-                double scaleWidth = (bounds.Width * 1.0) / SystemParameters.PrimaryScreenWidth;
96
-                double scaleHeight = (bounds.Height * 1.0) / SystemParameters.PrimaryScreenHeight;
97
-                int width = bounds.Width;
98
-                int height = bounds.Height;
99
-                if (ScreenSize.Size != new System.Drawing.Size(0, 0))
100
-                {
101
-                    width = (int)(ScreenSize.Size.Width * scaleWidth);
102
-                    height = (int)(ScreenSize.Size.Height * scaleHeight);
103
-                }
104
-                int l = (int)(ScreenSize.X * scaleWidth);
105
-                int t = (int)(ScreenSize.Y * scaleHeight);
106
-                //if (_Bitmap != null)
107
-                //{
108
-                //    _Bitmap.Dispose();
109
-                //}
110
-                Bitmap _Bitmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
111
-                using (Graphics g = Graphics.FromImage(_Bitmap))
112
-                {
113
-                    g.CopyFromScreen(l, t, 0, 0, _Bitmap.Size, CopyPixelOperation.SourceCopy);
114
-                    Compress(_Bitmap, ImageSavePath, level);
115
-                }
116
-                Uri uri = new Uri(ImageSavePath, UriKind.Absolute);
117
-                BitmapImage bimg = new BitmapImage(uri);
118
-                GC.Collect();
119
-                return bimg;
120
-            }
121
-            catch (Exception ex)
122
-            {
123
-                LogHelper.WriteErrLog("【截图】(GetBitmapSource)截图失败," + ex.Message, ex);
124
-                return null;
125
-            }
88
+            //try
89
+            //{
90
+            //    System.Drawing.Size bounds = PrimaryScreen.DESKTOP;
91
+            //    //if (string.IsNullOrEmpty(ImageSavePath))
92
+            //    //{
93
+            //    //    ImageSavePath = GetTempImagePath();//如果为空则指定临时存储路径
94
+            //    //}
95
+            //    double scaleWidth = (bounds.Width * 1.0) / SystemParameters.PrimaryScreenWidth;
96
+            //    double scaleHeight = (bounds.Height * 1.0) / SystemParameters.PrimaryScreenHeight;
97
+            //    int width = bounds.Width;
98
+            //    int height = bounds.Height;
99
+            //    if (ScreenSize.Size != new System.Drawing.Size(0, 0))
100
+            //    {
101
+            //        width = (int)(ScreenSize.Size.Width * scaleWidth);
102
+            //        height = (int)(ScreenSize.Size.Height * scaleHeight);
103
+            //    }
104
+            //    int l = (int)(ScreenSize.X * scaleWidth);
105
+            //    int t = (int)(ScreenSize.Y * scaleHeight);
106
+            //    //if (_Bitmap != null)
107
+            //    //{
108
+            //    //    _Bitmap.Dispose();
109
+            //    //}
110
+            //    Bitmap _Bitmap = new Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
111
+            //    using (Graphics g = Graphics.FromImage(_Bitmap))
112
+            //    {
113
+            //        g.CopyFromScreen(l, t, 0, 0, _Bitmap.Size, CopyPixelOperation.SourceCopy);
114
+            //        Compress(_Bitmap, ImageSavePath, level);
115
+            //    }
116
+            //    Uri uri = new Uri(ImageSavePath, UriKind.Absolute);
117
+            //    BitmapImage bimg = new BitmapImage(uri);
118
+            //    GC.Collect();
119
+            //    return bimg;
120
+            //}
121
+            //catch (Exception ex)
122
+            //{
123
+            //    //LogHelper.WriteErrLog("【截图】(GetBitmapSource)截图失败," + ex.Message, ex);
124
+            return null;
125
+            //}
126 126
         }
127 127
 
128 128
         //private static Bitmap _Bitmap = null;
@@ -164,7 +164,7 @@ namespace Common.system
164 164
         {
165 165
             if (level <= -1)
166 166
             {
167
-                int ImageCompressionLevel = int.Parse(ConfigurationManager.AppSettings["ImageCompressionLevel"]);
167
+                int ImageCompressionLevel = int.Parse(FileToolsCommon.GetConfigValue("ImageCompressionLevel"));
168 168
                 level = ImageCompressionLevel;
169 169
             }
170 170
             Stream s = new FileStream(destFile, FileMode.Create);
@@ -336,7 +336,6 @@ namespace Common.system
336 336
         #endregion 图片压缩
337 337
 
338 338
         #region 截屏指定UI控件
339
-
340 339
         /// <summary>
341 340
         /// 保存图片
342 341
         /// </summary>
@@ -344,7 +343,7 @@ namespace Common.system
344 343
         /// <param name="filePathName">图片保存地址 命名 1.png</param>
345 344
         /// <param name="width">保存宽</param>
346 345
         /// <param name="height">保存高</param>
347
-        private void SaveUIToImage(FrameworkElement ui, string filePathName, int width, int height)
346
+        public static void SaveUIToImage(FrameworkElement ui, string filePathName, int width, int height)
348 347
         {
349 348
             try
350 349
             {

+ 3
- 3
XHWK.Model/Model_Video.cs Целия файл

@@ -7,7 +7,7 @@
7 7
     {
8 8
         private string _videPath;
9 9
         private string _thumbnailPath;
10
-        private Emum_VideoType _videoType;
10
+        private Enum_VideoType _videoType;
11 11
         private Enum_WKVidetype _wkType;
12 12
         private string _RSTime;
13 13
         private string _videoSize;
@@ -22,7 +22,7 @@
22 22
         /// <summary>
23 23
         /// 视频类型
24 24
         /// </summary>
25
-        public Emum_VideoType VideoType { get => _videoType; set => _videoType = value; }
25
+        public Enum_VideoType VideoType { get => _videoType; set => _videoType = value; }
26 26
         /// <summary>
27 27
         /// 微课类型
28 28
         /// </summary>
@@ -39,7 +39,7 @@
39 39
     /// <summary>
40 40
     /// 视频格式类型
41 41
     /// </summary>
42
-    public enum Emum_VideoType
42
+    public enum Enum_VideoType
43 43
     {
44 44
         MP4 = 1,
45 45
         FlV = 2,

+ 2
- 2
XHWK.Model/Model_WKData.cs Целия файл

@@ -7,7 +7,7 @@ namespace XHWK.Model
7 7
         private string _wkName;
8 8
         private List<Model_Video> _videoList;
9 9
         private string _wkPath;
10
-        private string _wkDateTime;
10
+        private string _wkCreateDateTime;
11 11
         private string _drawDataPath;
12 12
         /// <summary>
13 13
         /// 微课名
@@ -24,7 +24,7 @@ namespace XHWK.Model
24 24
         /// <summary>
25 25
         /// 微课时间
26 26
         /// </summary>
27
-        public string WkDateTime { get => _wkDateTime; set => _wkDateTime = value; }
27
+        public string WkCreateDateTime { get => _wkCreateDateTime; set => _wkCreateDateTime = value; }
28 28
         /// <summary>
29 29
         /// 画板数据存储路径
30 30
         /// </summary>

+ 4
- 0
XHWK.WKTool/App.config Целия файл

@@ -10,7 +10,11 @@
10 10
     <add key="VideoSavePath" value="D:\星火微课" />
11 11
     <!--视频格式 1、MP4 2、FlV 3、AVI-->
12 12
     <add key="VideoType" value="1" />
13
+    <!--图片压缩质量-->
14
+    <add key="ImageCompressionLevel" value="50"/>
15
+    <!--用户名-->
13 16
     <add key="userName" value="" />
17
+    <!--记住密码-->
14 18
     <add key="isRemind" value="" />
15 19
   </appSettings>
16 20
 </configuration>

+ 5
- 8
XHWK.WKTool/App.cs Целия файл

@@ -26,18 +26,14 @@ namespace XHWK.WKTool
26 26
         /// </summary>
27 27
         public static Model_WKData WKData = null;
28 28
         /// <summary>
29
-        /// 讲解名称
30
-        /// </summary>
31
-        public static string WkName = null;
32
-        /// <summary>
33
-        /// 微课保存路径
34
-        /// </summary>
35
-        public static string WkSavePath = null;
36
-        /// <summary>
37 29
         /// 主页面
38 30
         /// </summary>
39 31
         public static XHMicroLessonSystemWindow W_XHMicroLessonSystemWindow = null;
40 32
         /// <summary>
33
+        /// 录屏工具
34
+        /// </summary>
35
+        public static FFMpeg FFmpeg = new FFMpeg();
36
+        /// <summary>
41 37
         /// 开始录像
42 38
         /// </summary>
43 39
         public static CountdownWindow W_CountdownWindow = null;
@@ -69,6 +65,7 @@ namespace XHWK.WKTool
69 65
         {
70 66
             // 定义Application对象作为整个应用程序入口
71 67
             Application app = new Application();
68
+            WKData = new Model_WKData();
72 69
             //app.DispatcherUnhandledException += MyApp_DispatcherUnhandledException;
73 70
             CreateAMicroLessonWindow win = new CreateAMicroLessonWindow();
74 71
             app.Run(win);

+ 12
- 12
XHWK.WKTool/CreateAMicroLessonWindow.xaml.cs Целия файл

@@ -34,7 +34,7 @@ namespace XHWK.WKTool
34 34
         /// <param name="e"></param>
35 35
         private void BtnDown_Click(object sender, RoutedEventArgs e)
36 36
         {
37
-
37
+            System.Environment.Exit(0);
38 38
         }
39 39
         /// <summary>
40 40
         /// 浏览
@@ -76,18 +76,19 @@ namespace XHWK.WKTool
76 76
                 System.Windows.MessageBox.Show("路径不可为空!");
77 77
                 return;
78 78
             }
79
-            if (!FileToolsCommon.IsLegalPath(txbExplainName.Text.Trim(), out string ErrMessage))
80
-            {
81
-                System.Windows.MessageBox.Show(ErrMessage);
82
-            }
83
-            string PathName = FileToolsCommon.GetLegalPath(txbStoragePath.Text) + txbExplainName.Text.Trim() + "/";
84
-            if (FileToolsCommon.IsExistDirectory(PathName))
79
+            //if (!FileToolsCommon.IsLegalPath(txbStoragePath.Text.Trim(), out string ErrMessage))
80
+            //{
81
+            //    System.Windows.MessageBox.Show(ErrMessage);
82
+            //    return;
83
+            //}
84
+            APP.WKData.WkPath = FileToolsCommon.GetLegalPath(txbStoragePath.Text) + txbExplainName.Text.Trim() + "/";
85
+            if (FileToolsCommon.IsExistDirectory(APP.WKData.WkPath))
85 86
             {
86 87
                 //微课已存在
87 88
                 MessageBoxResult dr = System.Windows.MessageBox.Show("讲解已存在是否覆盖?", "提示", MessageBoxButton.OKCancel);
88 89
                 if (dr == MessageBoxResult.OK)
89 90
                 {
90
-                    FileToolsCommon.DeleteDirectory(PathName);
91
+                    FileToolsCommon.DeleteDirectory(APP.WKData.WkPath);
91 92
                 }
92 93
                 else
93 94
                 {
@@ -96,12 +97,11 @@ namespace XHWK.WKTool
96 97
             }
97 98
             #endregion
98 99
             //创建文件夹
99
-            FileToolsCommon.CreateDirectory(PathName);
100
+            FileToolsCommon.CreateDirectory(APP.WKData.WkPath);
100 101
             //存储文件
101 102
             FileToolsCommon.SetConfigValue("VideoSavePath", txbStoragePath.Text);
102
-            APP.WkName = txbExplainName.Text;
103
-            APP.WkSavePath = PathName;
104
-            FileToolsCommon.CreateDirectory(APP.WkSavePath);
103
+            APP.WKData.WkName = txbExplainName.Text;
104
+            APP.WKData.WkCreateDateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
105 105
             if (APP.W_XHMicroLessonSystemWindow == null)
106 106
             {
107 107
                 APP.W_XHMicroLessonSystemWindow = new XHMicroLessonSystemWindow();

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

@@ -74,10 +74,10 @@
74 74
             <TextBlock Grid.Row="1" Text="01:35" FontSize="23" Foreground="#FFFFFF" Margin="30,50,0,0"/>
75 75
             <StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,0,15,0">
76 76
                 <Button x:Name="BtnRecordingScreen"  Cursor="Hand" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" Margin="0,0,15,0" Click="BtnRecordingScreen_Click">
77
-                    <Image Source="./Images/Toobar25.png"/>
77
+                    <Image x:Name="ImgRecordingScreen" Source="./Images/Toobar25.png"/>
78 78
                 </Button>
79 79
                 <Button x:Name="BtnStopRecordingScreen" Cursor="Hand" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" Margin="0,0,15,0" Click="BtnStopRecordingScreen_Click">
80
-                    <Image Source="./Images/Toobar14.png"/>
80
+                    <Image x:Name="ImgEndRecordingScreen" Source="./Images/Toobar14.png"/>
81 81
                 </Button>
82 82
                 <Button  Cursor="Hand" x:Name="btnBrush" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" Margin="0,0,10,0" Click="BtnBrush_Click">
83 83
                     <Image Source="./Images/Toobar8.png"/>

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

@@ -2,7 +2,7 @@
2 2
 
3 3
 using System;
4 4
 using System.Windows;
5
-
5
+using System.Windows.Media.Imaging;
6 6
 using XHWK.Model;
7 7
 
8 8
 namespace XHWK.WKTool
@@ -16,19 +16,19 @@ namespace XHWK.WKTool
16 16
         /// <summary>
17 17
         /// 视频存储路径
18 18
         /// </summary>
19
-        string RSPath;
19
+        string RecordingPath;
20 20
         /// <summary>
21
-        /// 是否正在录制
21
+        /// 视频保存名称
22 22
         /// </summary>
23
-        bool IsStartRS = false;
23
+        string VideoSavePathName;
24 24
         /// <summary>
25
-        /// 是否暂停
25
+        /// 是否首次录屏
26 26
         /// </summary>
27
-        bool IsSuspend = true;
27
+        bool IsFirstRS = true;
28 28
         /// <summary>
29
-        /// 录屏
29
+        /// 是否暂停
30 30
         /// </summary>
31
-        FFMpeg Ffmpeg = null;
31
+        bool IsSuspend = true;
32 32
         #endregion
33 33
 
34 34
         #region 初始化
@@ -46,41 +46,11 @@ namespace XHWK.WKTool
46 46
         {
47 47
             //隐藏画笔工具栏
48 48
             BtnToolbarDown_Click(null, null);
49
-            IsStartRS = false;
50
-            IsSuspend = true;
51
-            RSPath = null;
52
-            if (Ffmpeg == null)
53
-            {
54
-                Ffmpeg = new FFMpeg();
55
-            }
56 49
         }
57 50
         #endregion
58 51
 
59 52
         #region 录制
60 53
         /// <summary>
61
-        /// 停止录像
62
-        /// </summary>
63
-        /// <param name="sender"></param>
64
-        /// <param name="e"></param>
65
-        private void BtnStopRecordingScreen_Click(object sender, RoutedEventArgs e)
66
-        {
67
-            if (APP.W_XHMicroLessonSystemWindow == null)
68
-            {
69
-                APP.W_XHMicroLessonSystemWindow = new XHMicroLessonSystemWindow();
70
-            }
71
-            APP.W_XHMicroLessonSystemWindow.Show();
72
-            try
73
-            {
74
-                Ffmpeg.StopFFmpeg(RSPath);
75
-            }
76
-            catch (Exception ex)
77
-            {
78
-                MessageBox.Show(ex.Message);
79
-            }
80
-            IsStartRS = false;
81
-            Hide();
82
-        }
83
-        /// <summary>
84 54
         /// 开始或暂停录制
85 55
         /// </summary>
86 56
         /// <param name="sender"></param>
@@ -89,23 +59,31 @@ namespace XHWK.WKTool
89 59
         {
90 60
             if (IsSuspend)
91 61
             {
92
-                if(IsStartRS)
62
+                if(IsFirstRS)
93 63
                 {
64
+                    RecordingPath = APP.WKData.WkPath;
65
+                    //FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temp/");
66
+                    FileToolsCommon.CreateDirectory(RecordingPath);
67
+                    VideoSavePathName = RecordingPath + APP.WKData.WkName + "_录屏." + ((Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType"))).ToString();
68
+                    if (FileToolsCommon.IsExistFile(VideoSavePathName))
69
+                    {
70
+                        MessageBoxResult dr = System.Windows.MessageBox.Show("已存在录屏是否覆盖?", "提示", MessageBoxButton.OKCancel);
71
+                        if (dr == MessageBoxResult.OK)
72
+                        {
73
+                            FileToolsCommon.DeleteFile(VideoSavePathName);
74
+                        }
75
+                        else
76
+                        {
77
+                            return;
78
+                        }
79
+                    }
80
+                    IsFirstRS = false;
94 81
                 }
95
-                //timer = new DispatcherTimer();
96
-                //timer.Interval = TimeSpan.FromMilliseconds(1000);
97
-                //timer.Tick += Timer_Tick;//你的事件
98
-                //dt = Convert.ToDateTime("2020-01-01 00:00:00");
99
-                //FileToolsCommon.DeleteDirectory(RSPath);
100 82
                 IsSuspend = false;
101
-                IsStartRS = true;
102
-                BtnRecordingScreen.Content = "暂停录制";
83
+                ImgRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar25.png"));
103 84
                 try
104 85
                 {
105
-                    RSPath = APP.WkSavePath;
106
-                    FileToolsCommon.CreateDirectory(RSPath);
107
-                    RSPath += "." + ((Emum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType"))).ToString();
108
-                    Ffmpeg.StartRecordingVideo(RSPath);
86
+                    APP.FFmpeg.StartRecordingVideo(VideoSavePathName);
109 87
                 }
110 88
                 catch (Exception ex)
111 89
                 {
@@ -115,10 +93,10 @@ namespace XHWK.WKTool
115 93
             else
116 94
             {
117 95
                 IsSuspend = true;
96
+                ImgRecordingScreen.Source = new BitmapImage(new Uri("pack://application:,,,/Images/Toobar25.png"));
118 97
                 try
119 98
                 {
120
-                    Ffmpeg.SuspendFFmpeg();
121
-                    Ffmpeg.StopFFmpeg(RSPath);
99
+                    APP.FFmpeg.SuspendFFmpeg();
122 100
                 }
123 101
                 catch (Exception ex)
124 102
                 {
@@ -126,6 +104,29 @@ namespace XHWK.WKTool
126 104
                 }
127 105
             }
128 106
         }
107
+        /// <summary>
108
+        /// 停止录像
109
+        /// </summary>
110
+        /// <param name="sender"></param>
111
+        /// <param name="e"></param>
112
+        private void BtnStopRecordingScreen_Click(object sender, RoutedEventArgs e)
113
+        {
114
+            if (APP.W_XHMicroLessonSystemWindow == null)
115
+            {
116
+                APP.W_XHMicroLessonSystemWindow = new XHMicroLessonSystemWindow();
117
+            }
118
+            APP.W_XHMicroLessonSystemWindow.Show();
119
+            try
120
+            {
121
+                APP.FFmpeg.StopFFmpeg(VideoSavePathName);
122
+            }
123
+            catch (Exception ex)
124
+            {
125
+                MessageBox.Show(ex.Message);
126
+            }
127
+            IsFirstRS = true;
128
+            Hide();
129
+        }
129 130
         #endregion
130 131
 
131 132
         #region 画笔相关

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

@@ -68,7 +68,7 @@
68 68
                             <TextBlock Text="导入" FontSize="14" Foreground="#FFFFFF" HorizontalAlignment="Center"/>
69 69
                         </StackPanel>
70 70
                     </Button>
71
-                    <Button Cursor="Hand" x:Name="btnRecord" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" Margin="60,0,30,0" Click="BtnRecord_Click">
71
+                    <Button Cursor="Hand" x:Name="BtnRecord" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" Margin="60,0,30,0" Click="BtnRecord_Click">
72 72
                         <StackPanel Orientation="Vertical">
73 73
                             <Image x:Name="ImgRecord" Source="./Images/microLessonSystem_14.png"/>
74 74
                             <Image x:Name="ImgRecordTwo" Source="./Images/microLessonSystem_13.png" Visibility="Collapsed"/>
@@ -122,7 +122,7 @@
122 122
                 </StackPanel>
123 123
             </Grid>
124 124
             <!--主内容-->
125
-            <Grid Grid.Row="1" x:Name="gridMain"  Margin="20,0,20,0" Background="#FFFFFF" Height="793.700787401575" Width="1142.51968503937" Visibility="Visible">
125
+            <Grid Grid.Row="1" x:Name="GridMain"  Margin="20,0,20,0" Background="#FFFFFF" Height="793.700787401575" Width="1142.51968503937" Visibility="Visible">
126 126
                 <Grid.RowDefinitions>
127 127
                     <RowDefinition Height="auto"/>
128 128
                 </Grid.RowDefinitions>

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

@@ -14,6 +14,8 @@ using System.Windows.Input;
14 14
 using System.Windows.Media;
15 15
 using System.Windows.Media.Imaging;
16 16
 
17
+using XHWK.Model;
18
+
17 19
 namespace XHWK.WKTool
18 20
 {
19 21
     /// <summary>
@@ -53,6 +55,7 @@ namespace XHWK.WKTool
53 55
         /// </summary>
54 56
         public void Initialize()
55 57
         {
58
+
56 59
             //创建 DrawingAttributes 类的一个实例  
57 60
             drawingAttributes = new DrawingAttributes();
58 61
             //将 InkCanvas 的 DefaultDrawingAttributes 属性的值赋成创建的 DrawingAttributes 类的对象的引用  
@@ -183,7 +186,7 @@ namespace XHWK.WKTool
183 186
         /// <param name="e"></param>
184 187
         private void BtnSave_Click(object sender, RoutedEventArgs e)
185 188
         {
186
-            gridMain.Visibility = Visibility.Visible;
189
+            GridMain.Visibility = Visibility.Visible;
187 190
             gridSetUp.Visibility = Visibility.Collapsed;
188 191
         }
189 192
         /// <summary>
@@ -193,7 +196,7 @@ namespace XHWK.WKTool
193 196
         /// <param name="e"></param>
194 197
         private void BtnSetUp_Click(object sender, RoutedEventArgs e)
195 198
         {
196
-            gridMain.Visibility = Visibility.Collapsed;
199
+            GridMain.Visibility = Visibility.Collapsed;
197 200
             gridSetUp.Visibility = Visibility.Visible;
198 201
         }
199 202
         /// <summary>
@@ -427,6 +430,8 @@ namespace XHWK.WKTool
427 430
                 }
428 431
             }
429 432
         }
433
+        #region 录制窗口
434
+
430 435
         /// <summary>
431 436
         /// 录制窗口内容
432 437
         /// </summary>
@@ -439,7 +444,165 @@ namespace XHWK.WKTool
439 444
                 Login();
440 445
                 return;
441 446
             }
447
+
448
+        }
449
+        /// <summary>
450
+        /// 视频保存路径
451
+        /// </summary>
452
+        string RecordingPath;
453
+        /// <summary>
454
+        /// 图片保存路径
455
+        /// </summary>
456
+        string ImgPath;
457
+        /// <summary>
458
+        /// 音频保存路径名
459
+        /// </summary>
460
+        string AudioPathName;
461
+        /// <summary>
462
+        /// 视频保存路径名
463
+        /// </summary>
464
+        string VideoSavePathName;
465
+        /// <summary>
466
+        /// 暂停录制
467
+        /// </summary>
468
+        bool IsSuspendR = true;
469
+        /// <summary>
470
+        /// 是否首次录制
471
+        /// </summary>
472
+        bool IsFirstR = true;
473
+        /// <summary>
474
+        /// 图片
475
+        /// </summary>
476
+        int ImgNum = 0;
477
+        /// <summary>
478
+        /// 是否开始截图计数
479
+        /// </summary>
480
+        bool IsStartCount = false;
481
+
482
+        /// <summary>
483
+        /// 开始录制和暂停录制
484
+        /// </summary>
485
+        void StartRecord()
486
+        {
487
+            if (IsSuspendR)
488
+            {
489
+                if (IsFirstR)//是否第一次录制  初始化录制
490
+                {
491
+                    RecordingPath = APP.WKData.WkPath;
492
+                    ImgPath = APP.WKData.WkPath+"temp/Image/";
493
+                    AudioPathName = APP.WKData.WkPath + "temp/audio/";
494
+                    FileToolsCommon.DeleteDirectory(APP.WKData.WkPath + "temp/");
495
+                    FileToolsCommon.CreateDirectory(RecordingPath);
496
+                    FileToolsCommon.CreateDirectory(ImgPath);
497
+                    FileToolsCommon.CreateDirectory(AudioPathName);
498
+                    AudioPathName += APP.WKData.WkName+".MP3";
499
+                    VideoSavePathName = RecordingPath + APP.WKData.WkName+"_录制."+ ((Enum_VideoType)int.Parse(FileToolsCommon.GetConfigValue("VideoType"))).ToString();
500
+                    if(FileToolsCommon.IsExistFile(VideoSavePathName))
501
+                    {
502
+
503
+                    }
504
+                    IsFirstR = false;
505
+                    ImgNum = 0;
506
+                    new Thread(new ThreadStart(new Action(() =>
507
+                    {
508
+                        while (true)
509
+                        {
510
+                            Thread.Sleep(200);
511
+                            if (IsStartCount)
512
+                            {
513
+                                ImgNum++;
514
+                                Dispatcher.Invoke(() =>
515
+                                {
516
+                                    string FilePathName = ImgPath + ImgNum + ".png";
517
+                                    ImageHelper.SaveUIToImage(GridMain, FilePathName, (int)GridMain.ActualWidth, (int)GridMain.ActualHeight);
518
+                                });
519
+                            }
520
+                        }
521
+                    }))).Start();
522
+                }
523
+                //继续录制
524
+                IsSuspendR = false;
525
+                //BtnRecording.Content = "暂停录制";
526
+                ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_23.png"));
527
+                try
528
+                {
529
+                    APP.FFmpeg.StartRecordingAudio(AudioPathName);
530
+                    new Thread(new ThreadStart(new Action(() =>
531
+                    {
532
+                        Thread.Sleep(1000);
533
+                        //Dispatcher.Invoke(() =>
534
+                        //{
535
+                            IsStartCount = true;
536
+                        //});
537
+                    }))).Start();
538
+                }
539
+                catch (Exception ex)
540
+                {
541
+                    System.Windows.MessageBox.Show(ex.Message);
542
+                }
543
+            }
544
+            else
545
+            {
546
+                //暂停
547
+                IsSuspendR = true;
548
+                ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_14.png"));
549
+                try
550
+                {
551
+                    APP.FFmpeg.SuspendFFmpeg();
552
+                    new Thread(new ThreadStart(new Action(() =>
553
+                    {
554
+                        while (APP.FFmpeg.myProcess != null)
555
+                        {
556
+                            Thread.Sleep(100);
557
+                        }
558
+                        IsStartCount = false;
559
+                    }))).Start();
560
+                }
561
+                catch (Exception ex)
562
+                {
563
+                    System.Windows.MessageBox.Show(ex.Message);
564
+                }
565
+            }
442 566
         }
567
+        /// <summary>
568
+        /// 停止录制并生成录制文件
569
+        /// </summary>
570
+        void EndRecord()
571
+        {
572
+            IsFirstR = true;
573
+            IsSuspendR = true;
574
+            ImgRecord.Source = new BitmapImage(new Uri("pack://application:,,,/Images/microLessonSystem_14.png"));
575
+            try
576
+            {
577
+                APP.FFmpeg.StopFFmpeg(AudioPathName);
578
+                new Thread(new ThreadStart(new Action(() =>
579
+                {
580
+                    while (APP.FFmpeg.myProcess != null)
581
+                    {
582
+                        Thread.Sleep(100);
583
+                    }
584
+                    Dispatcher.Invoke(() =>
585
+                    {
586
+                        IsStartCount = false;
587
+                    });
588
+                }))).Start();
589
+
590
+                new Thread(new ThreadStart(new Action(() =>
591
+                {
592
+                    while (APP.FFmpeg.myProcess != null)
593
+                    {
594
+                        Thread.Sleep(100);
595
+                    }
596
+                }))).Start();
597
+                APP.FFmpeg.SynthesisVideo(ImgPath, AudioPathName, VideoSavePathName, 5, (int)GridMain.ActualWidth, (int)GridMain.ActualHeight);
598
+            }
599
+            catch (Exception ex)
600
+            {
601
+                System.Windows.MessageBox.Show(ex.Message);
602
+            }
603
+        }
604
+        #endregion
605
+
443 606
         /// <summary>
444 607
         /// 停止录制窗口内容
445 608
         /// </summary>

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