gavin.chen 2 жил өмнө
parent
commit
547e55e0bf

+ 13 - 7
src/flutter_sound_recorder.js

@@ -268,13 +268,19 @@ class FlutterSoundRecorder {
     this.currentRecordPath = path;
     this.currentRecordPath = path;
     var chunks = [];
     var chunks = [];
     var mediaStream;
     var mediaStream;
-    var deviceId = path.split(".")[0];
-    mediaStream = await navigator.mediaDevices.getUserMedia({
-      audio: {
-        deviceId: deviceId,
-      },
-      video: false,
-    });
+    /// 判断 path 是否包含 @,如果包含则表示指定了麦克风设备
+    if (path.indexOf("@") > 0) {
+      var deviceId = path.split("@")[1].split(".")[0];
+      mediaStream = await navigator.mediaDevices.getUserMedia({
+        audio: { deviceId: { ideal: deviceId } },
+        video: false,
+      });
+    } else {
+      mediaStream = await navigator.mediaDevices.getUserMedia({
+        audio: true,
+        video: false,
+      });
+    }
     me.mediaStream = mediaStream;
     me.mediaStream = mediaStream;
     const audioContext = new AudioContext();
     const audioContext = new AudioContext();
     const _audioSource = audioContext.createMediaStreamSource(mediaStream);
     const _audioSource = audioContext.createMediaStreamSource(mediaStream);