Browse Source

zhao:增加增加暂停功能,多视频录制合并

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

+ 138
- 45
Common/system/FFMpeg.cs View File

4
 using System.IO;
4
 using System.IO;
5
 using System.Linq;
5
 using System.Linq;
6
 using System.Text;
6
 using System.Text;
7
+using System.Threading;
8
+
7
 using VisioForge.Shared.NAudio.CoreAudioApi;
9
 using VisioForge.Shared.NAudio.CoreAudioApi;
8
 using VisioForge.Shared.NAudio.Wave;
10
 using VisioForge.Shared.NAudio.Wave;
9
 
11
 
11
 {
13
 {
12
     /// <summary>
14
     /// <summary>
13
     /// ffmpeg帮助类
15
     /// ffmpeg帮助类
16
+    /// 创建人:赵耀
17
+    /// 创建时间::2020年8月22日
14
     /// 需要安装\ffmpeg\bin\Setup Screen Capturer Recorder v0.12.10.exe
18
     /// 需要安装\ffmpeg\bin\Setup Screen Capturer Recorder v0.12.10.exe
15
     /// 本地调试需要配置环境变量 将ffmpeg.exe位置配置到环境变量的path中
19
     /// 本地调试需要配置环境变量 将ffmpeg.exe位置配置到环境变量的path中
16
     /// </summary>
20
     /// </summary>
24
         /// <summary>
28
         /// <summary>
25
         /// 录制屏幕
29
         /// 录制屏幕
26
         /// </summary>
30
         /// </summary>
27
-        /// <param name="PathName">文件存储路径</param>
28
-        /// <param name="VideoType">视频类型</param>
29
-        public void StartRecordingVideo(string PathName, string VideoType)
31
+        /// <param name="FilePath">文件存储路径</param>
32
+        public void StartRecordingVideo(string FilePath)
30
         {
33
         {
34
+            //路径
35
+            string Path = FileToolsCommon.GetDirectoryName(FilePath) + @"\";
36
+            string Extension = FileToolsCommon.GetIOExtension(FilePath);//扩展名
37
+            //文件保存路径
38
+            string PathName = GetFilePathName(FilePath);
31
             Process[] KillProcessArray = Process.GetProcessesByName("ffmpeg");
39
             Process[] KillProcessArray = Process.GetProcessesByName("ffmpeg");
32
             Debug.WriteLine(KillProcessArray.Length.ToString());
40
             Debug.WriteLine(KillProcessArray.Length.ToString());
33
             foreach (var KillProcess in KillProcessArray)
41
             foreach (var KillProcess in KillProcessArray)
38
             LogPath = CreateffmpegLog();
46
             LogPath = CreateffmpegLog();
39
             string MicrophoneName = GetMicrophone();
47
             string MicrophoneName = GetMicrophone();
40
             myProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath(@"/ffmpeg/bin/ffmpeg.exe");   //ffmpeg.exe的绝对路径
48
             myProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath(@"/ffmpeg/bin/ffmpeg.exe");   //ffmpeg.exe的绝对路径
41
-            switch (VideoType.ToUpper())
49
+            switch (Extension.ToUpper())
42
             {
50
             {
43
                 case "MP4":
51
                 case "MP4":
44
                     if (string.IsNullOrWhiteSpace(MicrophoneName))
52
                     if (string.IsNullOrWhiteSpace(MicrophoneName))
55
                 case "FLV":
63
                 case "FLV":
56
                     if (string.IsNullOrWhiteSpace(MicrophoneName))
64
                     if (string.IsNullOrWhiteSpace(MicrophoneName))
57
                     {
65
                     {
58
-                        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 "+ VideoType.ToLower() + " " + PathName;  //ffmpeg的参数
66
+                        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的参数
59
                     }
67
                     }
60
                     else
68
                     else
61
                     {
69
                     {
62
                         myProcess.StartInfo.Arguments = "-f dshow -i audio=\"virtual-audio-capturer\" -f dshow -i audio=\"" +
70
                         myProcess.StartInfo.Arguments = "-f dshow -i audio=\"virtual-audio-capturer\" -f dshow -i audio=\"" +
63
-                            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 " + VideoType.ToLower() + " " + PathName;  //ffmpeg的参数
71
+                            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的参数
64
                     }
72
                     }
65
                     break;
73
                     break;
66
                 default:
74
                 default:
120
         }
128
         }
121
 
129
 
122
         /// <summary>
130
         /// <summary>
123
-        /// 停录制
131
+        /// 停录制
124
         /// </summary>
132
         /// </summary>
125
-        public void StopFFmpeg()
133
+        public void SuspendFFmpeg()
126
         {
134
         {
127
-            //Thread.Sleep(3000);
128
             if (myProcess == null)
135
             if (myProcess == null)
129
                 return;
136
                 return;
130
             myProcess.StandardInput.WriteLine("q");//在这个进程的控制台中模拟输入q,用于暂停录制
137
             myProcess.StandardInput.WriteLine("q");//在这个进程的控制台中模拟输入q,用于暂停录制
135
         }
142
         }
136
 
143
 
137
         /// <summary>
144
         /// <summary>
138
-        /// 合成视频
145
+        /// 停止录制并合成文件
146
+        /// </summary>
147
+        /// <param name="FilePath">文件存储路径 必须与开始时的路径完全一致</param>
148
+        public void StopFFmpeg(string FilePath)
149
+        {
150
+            //文件完整路径
151
+            if (myProcess == null)
152
+                return;
153
+            myProcess.StandardInput.WriteLine("q");//在这个进程的控制台中模拟输入q,用于暂停录制
154
+            myProcess.Close();//关闭进程
155
+            myProcess.Dispose();//释放资源
156
+            myProcess = null;
157
+            Thread t1 = new Thread(MergeVideoOrAudio);
158
+            t1.Start(FilePath);
159
+            //文件合成
160
+        }
161
+
162
+        /// <summary>
163
+        /// 图片音频合成视频
139
         /// </summary>
164
         /// </summary>
140
         /// <param name="ImageListPath">图片列表位置 命名为1.png 2.png</param>
165
         /// <param name="ImageListPath">图片列表位置 命名为1.png 2.png</param>
141
         /// <param name="Mp3Path">MP3音频位置</param>
166
         /// <param name="Mp3Path">MP3音频位置</param>
143
         /// <param name="Frequency">每秒帧率</param>
168
         /// <param name="Frequency">每秒帧率</param>
144
         /// <param name="VideoWidth">视频宽度</param>
169
         /// <param name="VideoWidth">视频宽度</param>
145
         /// <param name="VideoHeight">视频高度</param>
170
         /// <param name="VideoHeight">视频高度</param>
146
-        /// <param name="VideoType">视频类型  MP4 FLV AVI</param>
147
-        private void SynthesisVideo(string ImageListPath, string Mp3Path, string VideoSavePath, int Frequency, int VideoWidth, int VideoHeight, string VideoType)
171
+        private void SynthesisVideo(string ImageListPath, string Mp3Path, string VideoSavePath, int Frequency, int VideoWidth, int VideoHeight)
172
+        {
173
+            Thread thread = new Thread(delegate ()
174
+            {
175
+                //// 允许不同线程间的调用
176
+                //Control.CheckForIllegalCrossThreadCalls = false;
177
+                Thread.Sleep(500);
178
+                string Extension = FileToolsCommon.GetIOExtension(VideoSavePath);//扩展名
179
+                Process[] KillProcessArray = Process.GetProcessesByName("ffmpeg");
180
+                Debug.WriteLine(KillProcessArray.Length.ToString());
181
+                foreach (var KillProcess in KillProcessArray)
182
+                {
183
+                    KillProcess.Kill();
184
+                }
185
+                myProcess = new Process();
186
+                LogPath = CreateffmpegLog();
187
+                this.myProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath(@"/ffmpeg/bin/ffmpeg.exe");   //ffmpeg.exe的绝对路径
188
+                switch (Extension.ToUpper())
189
+                {
190
+                    case "MP4":
191
+                        myProcess.StartInfo.Arguments = @"-y -r " + Frequency + " -i " +
192
+                            ImageListPath + @"%d.png -i " +
193
+                            Mp3Path + @" -s " + VideoWidth + "x" + VideoHeight + " -vcodec mpeg4 " +
194
+                            VideoSavePath;
195
+                        break;
196
+                    case "AVI":
197
+                        myProcess.StartInfo.Arguments = @"-y -r " + Frequency + " -i " +
198
+                            ImageListPath + @"%d.png -i " +
199
+                            Mp3Path + @" -s " + VideoWidth + "x" + VideoHeight + " -f AVI " +
200
+                            VideoSavePath;
201
+                        break;
202
+                    case "FLV":
203
+                        myProcess.StartInfo.Arguments = @"-y -r " + Frequency + " -i " +
204
+                            ImageListPath + @"%d.png -i " +
205
+                            Mp3Path + @" -s " + VideoWidth + "x" + VideoHeight + " -f FLV " +
206
+                            VideoSavePath;
207
+                        break;
208
+                    default:
209
+                        myProcess.StartInfo.Arguments = @"-y -r " + Frequency + " -i " +
210
+                            ImageListPath + @"%d.png -i " +
211
+                            Mp3Path + @" -s " + VideoWidth + "x" + VideoHeight + " -vcodec mpeg4 " +
212
+                            VideoSavePath;
213
+                        break;
214
+                }
215
+                myProcess.StartInfo.UseShellExecute = false;           //不使用操作系统外壳程序启动
216
+                myProcess.StartInfo.RedirectStandardError = true;      //重定向标准错误输出
217
+                myProcess.StartInfo.CreateNoWindow = true;             //不显示程序窗口
218
+                myProcess.StartInfo.RedirectStandardInput = true;      //用于模拟该进程控制台的输入
219
+                                                                       //外部程序(这里是FFMPEG)输出流时候产生的事件,这里是把流的处理过程转移到下面的方法中,详细请查阅MSDN
220
+                myProcess.ErrorDataReceived += new DataReceivedEventHandler(Output);
221
+                myProcess.Start();                 //启动线程
222
+                myProcess.BeginErrorReadLine();    //开始异步读取
223
+                myProcess.WaitForExit();           //阻塞等待进程结束
224
+                myProcess.Close();                 //关闭进程
225
+                myProcess.Dispose();               //释放资源
226
+                                                   //生成视频后删除图片保存列表
227
+                FileToolsCommon.DeleteDirectory(ImageListPath);
228
+            });
229
+        }
230
+
231
+        /// <summary>
232
+        /// 视频音频合成
233
+        /// </summary>
234
+        /// <param name="FilePath">存储路径</param>
235
+        void MergeVideoOrAudio(object FilePathobj)
148
         {
236
         {
237
+            Thread.Sleep(500);
238
+            //路径
239
+            string FilePath = (string)FilePathobj;
240
+            string Path = FileToolsCommon.GetDirectoryName(FilePath) + @"\";
149
             Process[] KillProcessArray = Process.GetProcessesByName("ffmpeg");
241
             Process[] KillProcessArray = Process.GetProcessesByName("ffmpeg");
150
             Debug.WriteLine(KillProcessArray.Length.ToString());
242
             Debug.WriteLine(KillProcessArray.Length.ToString());
151
             foreach (var KillProcess in KillProcessArray)
243
             foreach (var KillProcess in KillProcessArray)
153
                 KillProcess.Kill();
245
                 KillProcess.Kill();
154
             }
246
             }
155
             myProcess = new Process();
247
             myProcess = new Process();
156
-            LogPath=CreateffmpegLog();
248
+            LogPath = CreateffmpegLog();
157
             this.myProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath(@"/ffmpeg/bin/ffmpeg.exe");   //ffmpeg.exe的绝对路径
249
             this.myProcess.StartInfo.FileName = FileToolsCommon.GetFileAbsolutePath(@"/ffmpeg/bin/ffmpeg.exe");   //ffmpeg.exe的绝对路径
158
-            switch (VideoType.ToUpper())
159
-            {
160
-                case "MP4":
161
-                    myProcess.StartInfo.Arguments = @"-y -r " + Frequency + " -i " +
162
-                        ImageListPath + @"%d.png -i " +
163
-                        Mp3Path + @" -s " + VideoWidth + "x" + VideoHeight + " -vcodec mpeg4 " +
164
-                        VideoSavePath;
165
-                    break;
166
-                case "AVI":
167
-                    myProcess.StartInfo.Arguments = @"-y -r " + Frequency + " -i " +
168
-                        ImageListPath + @"%d.png -i " +
169
-                        Mp3Path + @" -s " + VideoWidth + "x" + VideoHeight + " -f AVI " +
170
-                        VideoSavePath;
171
-                    break;
172
-                case "FLV":
173
-                    myProcess.StartInfo.Arguments = @"-y -r " + Frequency + " -i " +
174
-                        ImageListPath + @"%d.png -i " +
175
-                        Mp3Path + @" -s " + VideoWidth + "x" + VideoHeight + " -f FLV " +
176
-                        VideoSavePath;
177
-                    break;
178
-                default:
179
-                    myProcess.StartInfo.Arguments = @"-y -r " + Frequency + " -i " +
180
-                        ImageListPath + @"%d.png -i " +
181
-                        Mp3Path + @" -s " + VideoWidth + "x" + VideoHeight + " -vcodec mpeg4 " +
182
-                        VideoSavePath;
183
-                    break;
184
-            }
250
+            myProcess.StartInfo.Arguments = "-f concat  -safe 0 -i " + Path + "temp/filelist.d -c copy " + FilePath;
185
             myProcess.StartInfo.UseShellExecute = false;           //不使用操作系统外壳程序启动
251
             myProcess.StartInfo.UseShellExecute = false;           //不使用操作系统外壳程序启动
186
             myProcess.StartInfo.RedirectStandardError = true;      //重定向标准错误输出
252
             myProcess.StartInfo.RedirectStandardError = true;      //重定向标准错误输出
187
             myProcess.StartInfo.CreateNoWindow = true;             //不显示程序窗口
253
             myProcess.StartInfo.CreateNoWindow = true;             //不显示程序窗口
193
             myProcess.WaitForExit();           //阻塞等待进程结束
259
             myProcess.WaitForExit();           //阻塞等待进程结束
194
             myProcess.Close();                 //关闭进程
260
             myProcess.Close();                 //关闭进程
195
             myProcess.Dispose();               //释放资源
261
             myProcess.Dispose();               //释放资源
196
-            //生成视频后删除图片保存列表
197
-            FileToolsCommon.DeleteDirectory(ImageListPath);
198
-            
199
         }
262
         }
200
-        
263
+
264
+        /// <summary>
265
+        /// 获取文件完整路径
266
+        /// </summary>
267
+        /// <param name="FilePath">文件路径</param>
268
+        /// <returns></returns>
269
+        string GetFilePathName(string FilePath)
270
+        {
271
+            //路径
272
+            string Path = FileToolsCommon.GetDirectoryName(FilePath) + @"\";
273
+            //Path.GetFileName(FilePath);//获取文件名
274
+            string Extension = FileToolsCommon.GetIOExtension(FilePath);//扩展名
275
+            string tempFilePath = Path + "temp/";
276
+            //创建临时目录
277
+            FileToolsCommon.CreateDirectory(tempFilePath);
278
+            //创建记录文件
279
+            if (!FileToolsCommon.IsExistFile(tempFilePath + "filelist.d"))
280
+            {
281
+                FileToolsCommon.CreateFile(tempFilePath + "filelist.d");
282
+            }
283
+            int num = 1;
284
+            string CompleteFilePath = tempFilePath + num + Extension;
285
+            while (FileToolsCommon.IsExistFile(CompleteFilePath))
286
+            {
287
+                num++;
288
+                CompleteFilePath = tempFilePath + num + Extension;
289
+            }
290
+            FileToolsCommon.AppendText(tempFilePath + "filelist.d", "file ./" + num + Extension + "\r\n");
291
+            return CompleteFilePath;
292
+        }
293
+
201
         /// <summary>
294
         /// <summary>
202
         /// 生成缩略图
295
         /// 生成缩略图
203
         /// </summary>
296
         /// </summary>
204
         /// <param name="VideoPath">视频地址</param>
297
         /// <param name="VideoPath">视频地址</param>
205
         /// <param name="ImagePath">图片地址</param>
298
         /// <param name="ImagePath">图片地址</param>
206
-        void GenerateThumbnails(string VideoPath,string ImagePath)
299
+        void GenerateThumbnails(string VideoPath, string ImagePath)
207
         {
300
         {
208
             Process[] KillProcessArray = Process.GetProcessesByName("ffmpeg");
301
             Process[] KillProcessArray = Process.GetProcessesByName("ffmpeg");
209
             Debug.WriteLine(KillProcessArray.Length.ToString());
302
             Debug.WriteLine(KillProcessArray.Length.ToString());

+ 43
- 5
Common/system/FileToolsCommon.cs View File

20
         /// </summary>
20
         /// </summary>
21
         /// <param name="Path">相对路径</param>
21
         /// <param name="Path">相对路径</param>
22
         /// <returns></returns>
22
         /// <returns></returns>
23
-        public static string GetFileAbsolutePath(string Path="")
23
+        public static string GetFileAbsolutePath(string Path = "")
24
         {
24
         {
25
             try
25
             try
26
             {
26
             {
155
                     Directory.CreateDirectory(directoryPath);
155
                     Directory.CreateDirectory(directoryPath);
156
                 }
156
                 }
157
             }
157
             }
158
-            catch (Exception)
158
+            catch (Exception ex)
159
             {
159
             {
160
-                throw  new ApplicationException("请使用管理员权限运行!");
160
+                throw new ApplicationException(ex.Message); //"请使用管理员权限运行!"
161
             }
161
             }
162
         }
162
         }
163
         #endregion
163
         #endregion
284
         /// 获取指定目录中所有文件列表  
284
         /// 获取指定目录中所有文件列表  
285
         /// </summary>  
285
         /// </summary>  
286
         /// <param name="directoryPath">指定目录的绝对路径</param>          
286
         /// <param name="directoryPath">指定目录的绝对路径</param>          
287
-        public static FileInfo[] GetFileInfos(string directoryPath,string files=null)
287
+        public static FileInfo[] GetFileInfos(string directoryPath, string files = null)
288
         {
288
         {
289
             //如果目录不存在,则抛出异常  
289
             //如果目录不存在,则抛出异常  
290
             if (!IsExistDirectory(directoryPath))
290
             if (!IsExistDirectory(directoryPath))
515
         public static string FileToString(string filePath)
515
         public static string FileToString(string filePath)
516
         {
516
         {
517
             //return FileToString(filePath, Encoding.Default); 
517
             //return FileToString(filePath, Encoding.Default); 
518
-            return FileToString(filePath, Encoding.UTF8); 
518
+            return FileToString(filePath, Encoding.UTF8);
519
         }
519
         }
520
         /// <summary>  
520
         /// <summary>  
521
         /// 将文件读取到字符串中  
521
         /// 将文件读取到字符串中  
554
             FileInfo fi = new FileInfo(filePath);
554
             FileInfo fi = new FileInfo(filePath);
555
             return fi.Name;
555
             return fi.Name;
556
         }
556
         }
557
+        /// <summary>  
558
+        /// 使用IO从文件的绝对路径中获取文件名( 包含扩展名 )  
559
+        /// </summary>  
560
+        /// <param name="filePath">文件的绝对路径</param>          
561
+        public static string GetIOFileName(string filePath)
562
+        {
563
+            return Path.GetFileName(filePath);
564
+        }
557
         #endregion
565
         #endregion
558
 
566
 
559
         #region 从文件的绝对路径中获取文件名( 不包含扩展名 )
567
         #region 从文件的绝对路径中获取文件名( 不包含扩展名 )
567
             FileInfo fi = new FileInfo(filePath);
575
             FileInfo fi = new FileInfo(filePath);
568
             return fi.Name.Split('.')[0];
576
             return fi.Name.Split('.')[0];
569
         }
577
         }
578
+        /// <summary>  
579
+        /// 使用IO从文件的绝对路径中获取文件名( 不包含扩展名 )  
580
+        /// </summary>  
581
+        /// <param name="filePath">文件的绝对路径</param>          
582
+        public static string GetIOFileNameNoExtension(string filePath)
583
+        {
584
+            return System.IO.Path.GetFileNameWithoutExtension(filePath);
585
+        }
570
         #endregion
586
         #endregion
571
 
587
 
572
         #region 从文件的绝对路径中获取扩展名
588
         #region 从文件的绝对路径中获取扩展名
580
             FileInfo fi = new FileInfo(filePath);
596
             FileInfo fi = new FileInfo(filePath);
581
             return fi.Extension;
597
             return fi.Extension;
582
         }
598
         }
599
+        /// <summary>  
600
+        /// 使用IO从文件的绝对路径中获取扩展名 
601
+        /// </summary>  
602
+        /// <param name="filePath">文件的绝对路径</param>          
603
+        public static string GetIOExtension(string filePath)
604
+        {
605
+            string Extension = System.IO.Path.GetExtension(filePath);
606
+            return Extension;
607
+        }
608
+
609
+        #endregion
610
+
611
+        #region 从文件的绝对路径中获取路径名
612
+        /// <summary>  
613
+        /// 从文件的绝对路径中获取扩展名  
614
+        /// </summary>  
615
+        /// <param name="filePath">文件的绝对路径</param>          
616
+        public static string GetDirectoryName(string filePath)
617
+        {
618
+            string DirectoryName = (System.IO.Path.GetDirectoryName(filePath) + "\\").Replace("\\", "/");
619
+            return DirectoryName;
620
+        }
583
         #endregion
621
         #endregion
584
 
622
 
585
         #region 清空指定目录
623
         #region 清空指定目录

+ 13
- 0
XHWK.WKTool/App.cs View File

14
 {
14
 {
15
     public partial class APP : Application
15
     public partial class APP : Application
16
     {
16
     {
17
+        /// <summary>
18
+        /// 主页面
19
+        /// </summary>
20
+        public static XHMicroLessonSystemWindow W_XHMicroLessonSystemWindow = null;
21
+        /// <summary>
22
+        /// 开始录像
23
+        /// </summary>
24
+        public static CountdownWindow W_CountdownWindow = null;
25
+        /// <summary>
26
+        /// 录像工具栏
27
+        /// </summary>
28
+        public static ScreenRecordingToolbarWindow W_ScreenRecordingToolbarWindow = null;
29
+
17
         [STAThread]
30
         [STAThread]
18
         private static void Main()
31
         private static void Main()
19
         {
32
         {

+ 1
- 1
XHWK.WKTool/CountdownWindow.xaml View File

14
         <SolidColorBrush Opacity="0.96" Color="#292C2E" />
14
         <SolidColorBrush Opacity="0.96" Color="#292C2E" />
15
     </Window.Background>
15
     </Window.Background>
16
     <Grid>
16
     <Grid>
17
-        <Image
17
+        <Image x:Name="ImgGif"
18
                     Width="600"
18
                     Width="600"
19
                     Height="600"
19
                     Height="600"
20
                     gifLib:ImageBehavior.AnimatedSource=".\Images\countdown.gif" MediaElement.MediaEnded="Image_MediaEnded"/>
20
                     gifLib:ImageBehavior.AnimatedSource=".\Images\countdown.gif" MediaElement.MediaEnded="Image_MediaEnded"/>

+ 20
- 14
XHWK.WKTool/CountdownWindow.xaml.cs View File

1
-using System;
1
+using AForge.Imaging;
2
+using Common.system;
3
+using System;
2
 using System.Collections.Generic;
4
 using System.Collections.Generic;
3
 using System.Linq;
5
 using System.Linq;
4
 using System.Text;
6
 using System.Text;
12
 using System.Windows.Media;
14
 using System.Windows.Media;
13
 using System.Windows.Media.Imaging;
15
 using System.Windows.Media.Imaging;
14
 using System.Windows.Shapes;
16
 using System.Windows.Shapes;
17
+using System.Windows.Threading;
15
 
18
 
16
 namespace XHWK.WKTool
19
 namespace XHWK.WKTool
17
 {
20
 {
20
     /// </summary>
23
     /// </summary>
21
     public partial class CountdownWindow : Window
24
     public partial class CountdownWindow : Window
22
     {
25
     {
26
+        DispatcherTimer timer = null;
23
         public CountdownWindow()
27
         public CountdownWindow()
24
         {
28
         {
25
             InitializeComponent();
29
             InitializeComponent();
26
-            
30
+            Initialize();
27
         }
31
         }
28
         public void Initialize()
32
         public void Initialize()
29
         {
33
         {
30
             //Thread.Sleep(1200);
34
             //Thread.Sleep(1200);
31
             //this.Hide();
35
             //this.Hide();
36
+            //MediaElement.Position
37
+            //((MediaElement)((object)ImgGif)).Position= TimeSpan.Zero;
38
+            timer = new DispatcherTimer();
39
+            timer.Interval = TimeSpan.FromMilliseconds(2500);
40
+            timer.Tick += Timer_Tick;
41
+            timer.Start();
32
         }
42
         }
43
+
44
+        private void Timer_Tick(object sender, EventArgs e)
45
+        {
46
+            this.Hide();
47
+            timer.Stop();
48
+        }
49
+
33
         /// <summary>
50
         /// <summary>
34
         /// 跳转页面
51
         /// 跳转页面
35
         /// </summary>
52
         /// </summary>
37
         /// <param name="e"></param>
54
         /// <param name="e"></param>
38
         private void Window_ContentRendered(object sender, EventArgs e)
55
         private void Window_ContentRendered(object sender, EventArgs e)
39
         {
56
         {
40
-            ScreenRecordingToolbarWindow win = new ScreenRecordingToolbarWindow();
41
-            win.Topmost = true;
42
-            win.Show();
43
-            //显示在右下角
44
-            double xpos = this.Left + this.Width - win.Width-10;
45
-            double ypos = this.Top + this.Height - win.Height - 60;
46
-
47
-
48
-            win.Left = xpos;
49
-            win.Top = ypos;
50
-            this.Hide();
51
-
52
             //Thread.Sleep(800);
57
             //Thread.Sleep(800);
53
             ////imgLoding.Source= new BitmapImage(new Uri("pack://application:,,/Images/countdown_2.png"));
58
             ////imgLoding.Source= new BitmapImage(new Uri("pack://application:,,/Images/countdown_2.png"));
54
             ////Thread.Sleep(300);
59
             ////Thread.Sleep(300);
61
 
66
 
62
         private void Image_MediaEnded(object sender, RoutedEventArgs e)
67
         private void Image_MediaEnded(object sender, RoutedEventArgs e)
63
         {
68
         {
69
+            System.Windows.Controls.Image img = (System.Windows.Controls.Image)sender;
64
             ((MediaElement)sender).Position = ((MediaElement)sender).Position.Add(TimeSpan.FromMilliseconds(10000));
70
             ((MediaElement)sender).Position = ((MediaElement)sender).Position.Add(TimeSpan.FromMilliseconds(10000));
65
         }
71
         }
66
     }
72
     }

+ 7
- 4
XHWK.WKTool/CreateAMicroLessonWindow.xaml.cs View File

73
         /// <param name="e"></param>
73
         /// <param name="e"></param>
74
         private void btnStart_Click(object sender, RoutedEventArgs e)
74
         private void btnStart_Click(object sender, RoutedEventArgs e)
75
         {
75
         {
76
-            XHMicroLessonSystemWindow win = new XHMicroLessonSystemWindow();
77
-            //win.Topmost = true;
78
-            win.ShowDialog();
79
-            this.Close();
76
+            if (APP.W_XHMicroLessonSystemWindow == null)
77
+            {
78
+                APP.W_XHMicroLessonSystemWindow = new XHMicroLessonSystemWindow();
79
+                //APP.W_XHMicroLessonSystemWindow .Topmost = true;
80
+            }
81
+            APP.W_XHMicroLessonSystemWindow.Show();
82
+            this.Hide();
80
         }
83
         }
81
         /// <summary>
84
         /// <summary>
82
         /// 窗体移动
85
         /// 窗体移动

+ 3
- 3
XHWK.WKTool/ScreenRecordingToolbarWindow.xaml View File

8
         Title="ScreenRecordingToolbarWindow" Height="450" Width="300" AllowsTransparency="True" 
8
         Title="ScreenRecordingToolbarWindow" Height="450" Width="300" AllowsTransparency="True" 
9
     ShowInTaskbar="False"
9
     ShowInTaskbar="False"
10
     WindowStartupLocation="CenterOwner"
10
     WindowStartupLocation="CenterOwner"
11
-    WindowStyle="None">
11
+    WindowStyle="None" Margin="0" Left="0" Top="0">
12
     <Window.Background>
12
     <Window.Background>
13
         <SolidColorBrush Opacity="0" Color="#292C2E" />
13
         <SolidColorBrush Opacity="0" Color="#292C2E" />
14
     </Window.Background>
14
     </Window.Background>
74
             <TextBlock Grid.Row="1" Text="01:35" FontSize="23" Foreground="#FFFFFF" Margin="30,50,0,0"/>
74
             <TextBlock Grid.Row="1" Text="01:35" FontSize="23" Foreground="#FFFFFF" Margin="30,50,0,0"/>
75
             <StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,0,15,0">
75
             <StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,0,15,0">
76
                 <Button Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" Margin="0,0,15,0">
76
                 <Button Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" Margin="0,0,15,0">
77
-                    <Image Source="./Images/Toobar25.png"/>
77
+                    <Image Source="Images/microLessonSystem_23.png"/>
78
                 </Button>
78
                 </Button>
79
-                <Button Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" Margin="0,0,15,0">
79
+                <Button x:Name="BtnStopRecordingScreen" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" Margin="0,0,15,0" Click="BtnStopRecordingScreen_Click">
80
                     <Image Source="./Images/Toobar14.png"/>
80
                     <Image Source="./Images/Toobar14.png"/>
81
                 </Button>
81
                 </Button>
82
                 <Button x:Name="btnBrush" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" Margin="0,0,10,0" Click="BtnBrush_Click">
82
                 <Button x:Name="btnBrush" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" Margin="0,0,10,0" Click="BtnBrush_Click">

+ 28
- 2
XHWK.WKTool/ScreenRecordingToolbarWindow.xaml.cs View File

1
-using System;
1
+using Common.system;
2
+using System;
2
 using System.Collections.Generic;
3
 using System.Collections.Generic;
3
 using System.Linq;
4
 using System.Linq;
4
 using System.Text;
5
 using System.Text;
23
         {
24
         {
24
             InitializeComponent();
25
             InitializeComponent();
25
         }
26
         }
27
+        public void Initialize()
28
+        {
29
+            BtnToolbarDown_Click(null, null);
30
+        }
26
         /// <summary>
31
         /// <summary>
27
         /// 画笔工具栏关闭事件
32
         /// 画笔工具栏关闭事件
28
         /// </summary>
33
         /// </summary>
39
         /// <param name="e"></param>
44
         /// <param name="e"></param>
40
         private void BtnBrush_Click(object sender, RoutedEventArgs e)
45
         private void BtnBrush_Click(object sender, RoutedEventArgs e)
41
         {
46
         {
42
-            gridToolbar.Visibility = Visibility.Visible;
47
+            if (gridToolbar.Visibility == Visibility.Visible)
48
+            {
49
+                gridToolbar.Visibility = Visibility.Hidden;
50
+            }
51
+            else
52
+            {
53
+                gridToolbar.Visibility = Visibility.Visible;
54
+            }
43
         }
55
         }
44
         /// <summary>
56
         /// <summary>
45
         /// 画笔粗细事件
57
         /// 画笔粗细事件
61
             gridColour.Visibility = Visibility.Visible;
73
             gridColour.Visibility = Visibility.Visible;
62
             gridThickness.Visibility = Visibility.Collapsed;
74
             gridThickness.Visibility = Visibility.Collapsed;
63
         }
75
         }
76
+        /// <summary>
77
+        /// 停止录像
78
+        /// </summary>
79
+        /// <param name="sender"></param>
80
+        /// <param name="e"></param>
81
+        private void BtnStopRecordingScreen_Click(object sender, RoutedEventArgs e)
82
+        {
83
+            if(APP.W_XHMicroLessonSystemWindow==null)
84
+            {
85
+                APP.W_XHMicroLessonSystemWindow = new XHMicroLessonSystemWindow();
86
+            }
87
+            APP.W_XHMicroLessonSystemWindow.Show();
88
+            Hide();
89
+        }
64
     }
90
     }
65
 }
91
 }

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

21
     /// </summary>
21
     /// </summary>
22
     public partial class XHMicroLessonSystemWindow : Window
22
     public partial class XHMicroLessonSystemWindow : Window
23
     {
23
     {
24
-        #region 字段
24
+        #region 初始值
25
         /// <summary>
25
         /// <summary>
26
         /// 文件目录窗口
26
         /// 文件目录窗口
27
         /// </summary>
27
         /// </summary>
97
         /// <param name="e"></param>
97
         /// <param name="e"></param>
98
         private void BtnScreenRecording_Click(object sender, RoutedEventArgs e)
98
         private void BtnScreenRecording_Click(object sender, RoutedEventArgs e)
99
         {
99
         {
100
-            CountdownWindow win = new CountdownWindow();
101
-            win.Topmost = true;
102
-            win.Show();
103
-            this.Close();
100
+            if (APP.W_CountdownWindow == null)
101
+            {
102
+                APP.W_CountdownWindow = new CountdownWindow();
103
+                //APP.W_CountdownWindow.Topmost = true;
104
+            }
105
+            else
106
+            {
107
+                APP.W_CountdownWindow.Initialize();
108
+                APP.W_CountdownWindow.Topmost = true;
109
+            }
110
+            APP.W_CountdownWindow.Show();
111
+
112
+            if (APP.W_ScreenRecordingToolbarWindow == null)
113
+            {
114
+                APP.W_ScreenRecordingToolbarWindow = new ScreenRecordingToolbarWindow();
115
+                APP.W_ScreenRecordingToolbarWindow.Topmost = true;
116
+                APP.W_ScreenRecordingToolbarWindow.Initialize();
117
+
118
+            }
119
+            else
120
+            {
121
+                APP.W_ScreenRecordingToolbarWindow.Initialize();
122
+            }
123
+            //显示在右下角
124
+            //APP.W_ScreenRecordingToolbarWindow.Left= PrimaryScreen.DESKTOP.Width - APP.W_ScreenRecordingToolbarWindow.Width - 10;
125
+            //APP.W_ScreenRecordingToolbarWindow.Top= PrimaryScreen.DESKTOP.Height - APP.W_ScreenRecordingToolbarWindow.Height - 60;
126
+            this.Hide();
127
+            Hide();
104
         }
128
         }
105
         /// <summary>
129
         /// <summary>
106
         /// 上传事件
130
         /// 上传事件

+ 1
- 0
XHWK.WKTool/XHWK.WKTool.csproj View File

58
     </Reference>
58
     </Reference>
59
     <Reference Include="System" />
59
     <Reference Include="System" />
60
     <Reference Include="System.Data" />
60
     <Reference Include="System.Data" />
61
+    <Reference Include="System.Drawing" />
61
     <Reference Include="System.Windows.Forms" />
62
     <Reference Include="System.Windows.Forms" />
62
     <Reference Include="System.Xml" />
63
     <Reference Include="System.Xml" />
63
     <Reference Include="Microsoft.CSharp" />
64
     <Reference Include="Microsoft.CSharp" />

Loading…
Cancel
Save