浏览代码

添加设备检测

tags/3.0.0
张剑 3 年前
父节点
当前提交
19bdda8013

+ 2
- 2
XHWK.WKTool/App.config 查看文件

@@ -9,8 +9,8 @@
9 9
     <!--参数是否加密 0不加密 1加密-->
10 10
     <add key="IsParameterEncryption" value="0" />
11 11
     <!--版本号-->
12
-    <add key="VersionCode" value="86" />
13
-    <add key="VersionName" value="2.6.6" />
12
+    <add key="VersionCode" value="87" />
13
+    <add key="VersionName" value="2.6.7" />
14 14
     <!--皮肤样式 0白 1蓝 2黑色 -->
15 15
     <add key="SkinStyle" value="0" />
16 16
     <!--是否输出视频记录日志:0否-->

+ 97
- 4
XHWK.WKTool/Utils/ZAudioRecordHelper.cs 查看文件

@@ -1,4 +1,6 @@
1 1
 using System;
2
+using System.IO;
3
+using System.Threading;
2 4
 
3 5
 using NAudio.Wave;
4 6
 
@@ -33,7 +35,7 @@ namespace XHWK.WKTool.Utils
33 35
 
34 36
         string audioFile = "";
35 37
 
36
-        public ZAudioRecordHelper(string filePath,RecordType type)
38
+        public ZAudioRecordHelper(string filePath, RecordType type)
37 39
         {
38 40
             _t = type;
39 41
             audioFile = filePath;
@@ -54,7 +56,8 @@ namespace XHWK.WKTool.Utils
54 56
                     //开始录音,写数据
55 57
                     waveIn.DataAvailable += (s, a) =>
56 58
                     {
57
-                        if (_state == RecordState.start) {
59
+                        if (_state == RecordState.start)
60
+                        {
58 61
                             writer.Write(a.Buffer, 0, a.BytesRecorded);
59 62
                         }
60 63
                     };
@@ -89,7 +92,7 @@ namespace XHWK.WKTool.Utils
89 92
                         capture.Dispose();
90 93
                     };
91 94
                     capture.StartRecording();
92
-                } 
95
+                }
93 96
             }
94 97
             catch (Exception ex)
95 98
             {
@@ -123,8 +126,98 @@ namespace XHWK.WKTool.Utils
123 126
         /// <summary>
124 127
         /// 恢复录制
125 128
         /// </summary>
126
-        public void ResumeRecordAudio() {
129
+        public void ResumeRecordAudio()
130
+        {
127 131
             _state = RecordState.start;
128 132
         }
133
+
134
+        /// <summary>
135
+        /// 设备是否可用
136
+        /// </summary>
137
+        /// <param name="type"></param>
138
+        /// <returns></returns>
139
+        public static bool IsDeviceGood(RecordType type)
140
+        {
141
+            string tempPath = Path.GetTempPath();
142
+            Console.WriteLine("临时路径:" + tempPath);
143
+            WaveInEvent mWaveIn = null;
144
+            WaveFileWriter mWriter = null;
145
+            WasapiLoopbackCapture mCapture = null;
146
+            try
147
+            {
148
+                if (type == RecordType.microphone)
149
+                {
150
+                    string mAudioFile = Path.Combine(tempPath, "_microphone.mp3");
151
+
152
+                    mWaveIn = new WaveInEvent();
153
+                    mWriter = new WaveFileWriter(mAudioFile, mWaveIn.WaveFormat);
154
+                    //开始录音,写数据
155
+                    mWaveIn.DataAvailable += (s, a) =>
156
+                    {
157
+                        mWriter.Write(a.Buffer, 0, a.BytesRecorded);
158
+                    };
159
+
160
+                    //结束录音
161
+                    mWaveIn.RecordingStopped += (s, a) =>
162
+                    {
163
+                        mWriter.Dispose();
164
+                        mWriter = null;
165
+                        mWaveIn.Dispose();
166
+
167
+                        if (File.Exists(mAudioFile))
168
+                        {
169
+                            File.Delete(mAudioFile);
170
+                        }
171
+                    };
172
+
173
+                    mWaveIn.StartRecording();
174
+
175
+                    ThreadPool.QueueUserWorkItem(o =>
176
+                    {
177
+                        Thread.Sleep(200);
178
+                        mWaveIn.StopRecording();
179
+                    });
180
+                }
181
+                else
182
+                {
183
+                    string mAudioFile = Path.Combine(tempPath, "_loudspeaker.mp3");
184
+                    mCapture = new WasapiLoopbackCapture();
185
+                    mWriter = new WaveFileWriter(mAudioFile, mCapture.WaveFormat);
186
+
187
+                    mCapture.DataAvailable += (s, a) =>
188
+                    {
189
+                        mWriter.Write(a.Buffer, 0, a.BytesRecorded);
190
+                    };
191
+                    //结束录音
192
+                    mCapture.RecordingStopped += (s, a) =>
193
+                    {
194
+                        mWriter.Dispose();
195
+                        mWriter = null;
196
+                        mCapture.Dispose();
197
+
198
+                        if (File.Exists(mAudioFile))
199
+                        {
200
+                            File.Delete(mAudioFile);
201
+                        }
202
+                    };
203
+                    mCapture.StartRecording();
204
+                    ThreadPool.QueueUserWorkItem(o =>
205
+                    {
206
+                        Thread.Sleep(200);
207
+                        mCapture.StopRecording();
208
+                    });
209
+                }
210
+            }
211
+            catch (Exception ex)
212
+            {
213
+                if (mWriter != null) {
214
+                    mWriter.Dispose();
215
+                    mWriter = null;
216
+                }
217
+                return false;
218
+            }
219
+
220
+            return true;
221
+        }
129 222
     }
130 223
 }

+ 24
- 6
XHWK.WKTool/XHMicroLessonSystemWindow.xaml.cs 查看文件

@@ -147,6 +147,7 @@ namespace XHWK.WKTool
147 147
             new Aspose.Slides.License().SetLicense(new MemoryStream(license));
148 148
             InitializeComponent();
149 149
 
150
+
150 151
             #region 调整文字大小
151 152
 
152 153
             APP.PageContextData.WordSize20 = 20.00;
@@ -3083,13 +3084,22 @@ namespace XHWK.WKTool
3083 3084
         /// <param name="e"></param>
3084 3085
         private void BtnScreenRecording_Click(object sender, RoutedEventArgs e)
3085 3086
         {
3087
+            bool microphoneGood = ZAudioRecordHelper.IsDeviceGood(ZAudioRecordHelper.RecordType.microphone);
3088
+            bool loudspeakerGood = ZAudioRecordHelper.IsDeviceGood(ZAudioRecordHelper.RecordType.loudspeaker);
3089
+
3090
+            if (!microphoneGood) {
3091
+                MessageBox.Show("麦克风不可用");
3092
+                return;
3093
+            }
3094
+
3095
+            if (!loudspeakerGood)
3096
+            {
3097
+                MessageBox.Show("扬声器不可用");
3098
+                return;
3099
+            }
3100
+
3086 3101
             Record();
3087
-            //if (!APP.CheckScreenCapturerRecorder())
3088
-            //{
3089
-            //    MessageWindow.Show("使用此功能需安装环境,请在确定后依次点击“OK-Next>-Next>Install”完成安装!");
3090
-            //    //APP.InstallScreenCapturerRecorder();
3091
-            //    return;
3092
-            //}
3102
+            
3093 3103
 
3094 3104
             k_hook.Stop();
3095 3105
             if (APP.W_ScreenRecordingToolbarWindow == null)
@@ -3220,6 +3230,14 @@ namespace XHWK.WKTool
3220 3230
 
3221 3231
             #endregion 防止连击
3222 3232
 
3233
+            bool microphoneGood = ZAudioRecordHelper.IsDeviceGood(ZAudioRecordHelper.RecordType.microphone);
3234
+
3235
+            if (!microphoneGood)
3236
+            {
3237
+                MessageBox.Show("麦克风不可用");
3238
+                return;
3239
+            }
3240
+
3223 3241
             Record();
3224 3242
 
3225 3243
             if (APP.PageContextData.currpage > 0)

+ 1
- 1
打包脚本/Inno Setup星火微课.iss 查看文件

@@ -3,7 +3,7 @@
3 3
 
4 4
 #define MyAppName "星火微课"  
5 5
 #define MyAppDir "xhwk"
6
-#define MyAppVersion "2.6.6"
6
+#define MyAppVersion "2.6.7"
7 7
 #define MyAppPublisher "河南星火燎原软件科技有限公司"
8 8
 #define MyAppURL "http://www.xhkjedu.com/"
9 9
 #define MySourcePath "D:\Project\C#\xhwkclient\XHWK.WKTool\bin\x86\Debug\"

正在加载...
取消
保存