Skip to content

Commit

Permalink
Fix Audio output list is empty in android (livekit#231)
Browse files Browse the repository at this point in the history
This used to throw a state error under android becuase the audio output list is empty
  • Loading branch information
moham96 authored Jan 3, 2023
1 parent 7a8ef9f commit 01145bf
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/src/hardware/hardware.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:async';

import 'package:collection/collection.dart';
import 'package:flutter_webrtc/flutter_webrtc.dart' as rtc;

class MediaDevice {
Expand Down Expand Up @@ -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');
});
}

Expand Down Expand Up @@ -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);
}
}

0 comments on commit 01145bf

Please sign in to comment.