onInit method
override
Called immediately after the widget is allocated in memory. You might use this to initialize something for the controller.
Implementation
@override
void onInit() async {
_devicesSubscription = MediaUtils.onDeviceChange.listen((e) {
devices.value = e.output().toList();
selected.value = devices.firstWhereOrNull((e) => e.id() == _output);
});
_worker = ever(_settingsRepository.mediaSettings, (e) {
if (e != null) {
_output = e.outputDevice;
selected.value = devices.firstWhereOrNull((e) => e.id() == _output);
}
});
try {
// Output devices are permitted to be use when requesting a microphone
// permission.
_permissionSubscription = await WebUtils.microphonePermission();
devices.value = await MediaUtils.enumerateDevices(
MediaDeviceKind.audioOutput,
);
selected.value = devices.firstWhereOrNull((e) => e.id() == _output);
} on UnsupportedError {
error.value = 'err_media_devices_are_null'.l10n;
} catch (e) {
if (e.toString().contains('Permission denied')) {
error.value = 'err_microphone_permission_denied'.l10n;
} else {
error.value = e.toString();
rethrow;
}
}
super.onInit();
}