Fix Audio output list is empty in android (#231)

This used to throw a state error under android becuase the audio output list is empty
This commit is contained in:
MOHAMMAD RASIM
2023-01-03 04:55:41 +03:00
committed by GitHub
parent 7a8ef9fd0c
commit 01145bf36c
+7 -6
View File
@@ -1,5 +1,6 @@
import 'dart:async';
import 'package:collection/collection.dart';
import 'package:flutter_webrtc/flutter_webrtc.dart' as rtc;
class MediaDevice {
@@ -34,11 +35,11 @@ class Hardware {
rtc.navigator.mediaDevices.ondevicechange = _onDeviceChange;
enumerateDevices().then((devices) {
selectedAudioInput ??=
devices.where((element) => element.kind == 'audioinput').first;
devices.firstWhereOrNull((element) => element.kind == 'audioinput');
selectedAudioOutput ??=
devices.where((element) => element.kind == 'audiooutput').first;
devices.firstWhereOrNull((element) => element.kind == 'audiooutput');
selectedVideoInput ??=
devices.where((element) => element.kind == 'videoinput').first;
devices.firstWhereOrNull((element) => element.kind == 'videoinput');
});
}
@@ -124,11 +125,11 @@ class Hardware {
dynamic _onDeviceChange(dynamic _) async {
var devices = await enumerateDevices();
selectedAudioInput ??=
devices.where((element) => element.kind == 'audioinput').first;
devices.firstWhereOrNull((element) => element.kind == 'audioinput');
selectedAudioOutput ??=
devices.where((element) => element.kind == 'audiooutput').first;
devices.firstWhereOrNull((element) => element.kind == 'audiooutput');
selectedVideoInput ??=
devices.where((element) => element.kind == 'videoinput').first;
devices.firstWhereOrNull((element) => element.kind == 'videoinput');
onDeviceChange.add(devices);
}
}