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:
@@ -1,5 +1,6 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:collection/collection.dart';
|
||||||
import 'package:flutter_webrtc/flutter_webrtc.dart' as rtc;
|
import 'package:flutter_webrtc/flutter_webrtc.dart' as rtc;
|
||||||
|
|
||||||
class MediaDevice {
|
class MediaDevice {
|
||||||
@@ -34,11 +35,11 @@ class Hardware {
|
|||||||
rtc.navigator.mediaDevices.ondevicechange = _onDeviceChange;
|
rtc.navigator.mediaDevices.ondevicechange = _onDeviceChange;
|
||||||
enumerateDevices().then((devices) {
|
enumerateDevices().then((devices) {
|
||||||
selectedAudioInput ??=
|
selectedAudioInput ??=
|
||||||
devices.where((element) => element.kind == 'audioinput').first;
|
devices.firstWhereOrNull((element) => element.kind == 'audioinput');
|
||||||
selectedAudioOutput ??=
|
selectedAudioOutput ??=
|
||||||
devices.where((element) => element.kind == 'audiooutput').first;
|
devices.firstWhereOrNull((element) => element.kind == 'audiooutput');
|
||||||
selectedVideoInput ??=
|
selectedVideoInput ??=
|
||||||
devices.where((element) => element.kind == 'videoinput').first;
|
devices.firstWhereOrNull((element) => element.kind == 'videoinput');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,11 +125,11 @@ class Hardware {
|
|||||||
dynamic _onDeviceChange(dynamic _) async {
|
dynamic _onDeviceChange(dynamic _) async {
|
||||||
var devices = await enumerateDevices();
|
var devices = await enumerateDevices();
|
||||||
selectedAudioInput ??=
|
selectedAudioInput ??=
|
||||||
devices.where((element) => element.kind == 'audioinput').first;
|
devices.firstWhereOrNull((element) => element.kind == 'audioinput');
|
||||||
selectedAudioOutput ??=
|
selectedAudioOutput ??=
|
||||||
devices.where((element) => element.kind == 'audiooutput').first;
|
devices.firstWhereOrNull((element) => element.kind == 'audiooutput');
|
||||||
selectedVideoInput ??=
|
selectedVideoInput ??=
|
||||||
devices.where((element) => element.kind == 'videoinput').first;
|
devices.firstWhereOrNull((element) => element.kind == 'videoinput');
|
||||||
onDeviceChange.add(devices);
|
onDeviceChange.add(devices);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user