Procházet zdrojové kódy

支持麦克风切换

gavin.chen před 2 roky
rodič
revize
1c1e2fe025

+ 19 - 9
lib/hardware_detection/controller.dart

@@ -177,13 +177,10 @@ class HardwareDetectionController extends GetxController {
       }
     });
     if (state.currentMicrophone == null) return;
-    // TRTCCloud trtcCloud = (await TRTCCloud.sharedInstance())!;
-    // TXDeviceManager deviceManager = trtcCloud.getDeviceManager();
-    // deviceManager.setCurrentDevice(0, state.currentMicrophone!.id);
-    // if (state.detectingMicrophone) {
-    //   _stopRecordMicrophone();
-    //   _startRecordMicrophone();
-    // }
+    if (state.detectingMicrophone) {
+      await _stopRecordMicrophone();
+      _startRecordMicrophone();
+    }
   }
 
   /// 选择扬声器
@@ -297,6 +294,9 @@ class HardwareDetectionController extends GetxController {
     return deviceList;
   }
 
+  /// TODO 调用 js 获取所有设备列表
+  /// const devices = await navigator.mediaDevices.enumerateDevices();
+
   /// 打开当前选中的摄像头
   _openSelectedCamera() {
     bool found = false;
@@ -365,12 +365,22 @@ class HardwareDetectionController extends GetxController {
 
   // 开始采集麦克风音频
   void _startRecordMicrophone() async {
+    /// 获取到当前选中的麦克风的id
+    if (state.currentMicrophone == null) {
+      return;
+    }
+    final String fileNameWithMicrophoneId =
+        "${state.currentMicrophone!.id}.webm";
+
+    ///  将麦克风的id作为文件名,web端的record会做处理,会将文件名作为选中的麦克风id进行设置
     await flutterRecorder.startRecorder(
-        toFile: _mPath, codec: _codec, audioSource: AudioSource.microphone);
+        toFile: fileNameWithMicrophoneId,
+        codec: _codec,
+        audioSource: AudioSource.microphone);
   }
 
   /// 停止采集麦克风音频
-  void _stopRecordMicrophone() async {
+  Future<void> _stopRecordMicrophone() async {
     await flutterRecorder.stopRecorder();
   }
 

+ 0 - 3
lib/hardware_detection/widgets/microphone_wave.dart

@@ -42,9 +42,6 @@ class _MicrophoneWaveState extends State<MicrophoneWave>
       ..addListener(() {
         setState(() {});
       });
-
-    /// 如果没有分贝数据,请参考 https://github.com/Canardoux/flutter_sound/issues/838
-    /// 将  flutter_sound_web 的 flutter_sound_recorder.js 从 flutter_sound_web/js/flutter_sound 复制到 flutter_sound_web/src
     _recorderSubscription =
         widget.recorder.onProgress!.listen((RecordingDisposition e) {
       /// 输出响度,响度范围是0-120

+ 4 - 0
pubspec.yaml

@@ -21,6 +21,10 @@ dependencies:
 
 # 需要覆盖版本号的依赖
 dependency_overrides:
+  flutter_sound_web:
+    git:
+      url: http://git.ius.plus/gavin.chen/fis_flutter_sound_web_magic.git
+      ref: bc63423
   tencent_trtc_cloud:
     git:
       url: http://git.ius.plus/melon.yin/fis_trtc_magic.git