瀏覽代碼

update js

gavin.chen 2 年之前
父節點
當前提交
547e55e0bf
共有 1 個文件被更改,包括 13 次插入7 次删除
  1. 13 7
      src/flutter_sound_recorder.js

+ 13 - 7
src/flutter_sound_recorder.js

@@ -268,13 +268,19 @@ class FlutterSoundRecorder {
     this.currentRecordPath = path;
     var chunks = [];
     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;
     const audioContext = new AudioContext();
     const _audioSource = audioContext.createMediaStreamSource(mediaStream);