瀏覽代碼

zhao:解决麦克风设备名字过长限制导致找不到麦克风设备的问题

tags/录制修改前
耀 4 年之前
父節點
當前提交
11d074d1f9
共有 1 個文件被更改,包括 29 次插入2 次删除
  1. 29
    2
      Common/system/FFMpeg.cs

+ 29
- 2
Common/system/FFMpeg.cs 查看文件

@@ -1,6 +1,7 @@
1 1
 using System;
2 2
 using System.Collections.Generic;
3 3
 using System.Diagnostics;
4
+using System.Linq;
4 5
 using System.Text;
5 6
 using System.Threading;
6 7
 
@@ -104,7 +105,7 @@ namespace Common.system
104 105
             }
105 106
             if (IsRecordMicrophone)
106 107
             {
107
-                MicrophoneName = GetInDeviceFull();
108
+                MicrophoneName = GetInDeviceName();
108 109
                 if (!string.IsNullOrWhiteSpace(MicrophoneName))
109 110
                 {
110 111
                     MicrophoneStr = "-f dshow -i audio=\"" + MicrophoneName + "\" -filter_complex amix=inputs=2:duration=first:dropout_transition=2 ";
@@ -201,7 +202,7 @@ namespace Common.system
201 202
             if (StartRecordAudio(audioMicrophonePath))
202 203
             {
203 204
                 IsRecordMicrophone = true;
204
-                MicrophoneName = GetInDeviceFull();
205
+                MicrophoneName = GetInDeviceName();
205 206
             }
206 207
             else
207 208
             {
@@ -798,6 +799,32 @@ namespace Common.system
798 799
             }
799 800
         }
800 801
 
802
+        /// <summary>
803
+        /// 获取声音输入设备
804
+        /// </summary>
805
+        /// <returns></returns>
806
+        public static string GetInDeviceName()
807
+        {
808
+            var devices = new List<WaveInCapabilities>();
809
+            int waveInDevices = WaveIn.DeviceCount;
810
+            for (int i = 0; i < waveInDevices; i++)
811
+            {
812
+                devices.Add(WaveIn.GetCapabilities(i));
813
+            }
814
+            List<string> devs = new List<string>();
815
+            devs = devices.Select(item => item.ProductName).ToList();
816
+
817
+            if (devs.Count > 0)
818
+            {
819
+                byte[] buffer = Encoding.UTF8.GetBytes(devs[0]);
820
+                string MicrophoneName = Encoding.UTF8.GetString(buffer); // 统一使用UTF-8
821
+                return MicrophoneName;
822
+            }
823
+            else
824
+            {
825
+                return "";
826
+            }
827
+        }
801 828
         /// <summary>
802 829
         /// 获取声音输入设备完整名称
803 830
         /// </summary>

Loading…
取消
儲存