Closed toebgen closed 2 years ago
Thanks for reporting. Let's see:
/// (UNTESTED) Requires API level 28
Future<List<AndroidMicrophoneInfo>> getMicrophones() async {
return ((await _channel.invokeListMethod<Map<String, dynamic>>(
'getMicrophones')) as List<dynamic>)
.map((raw) => AndroidMicrophoneInfo(
description: raw['description'],
id: raw['id'],
type: raw['type'],
address: raw['address'],
location: decodeEnum(
AndroidMicrophoneLocation.values, raw['location'],
defaultValue: AndroidMicrophoneLocation.unknown),
group: raw['group'],
indexInTheGroup: raw['indexInTheGroup'],
position: (raw['position'] as List<dynamic>).cast<double>(),
orientation: (raw['orientation'] as List<dynamic>).cast<double>(),
frequencyResponse: (raw['frequencyResponse'] as List<dynamic>)
.map((dynamic item) => (item as List<dynamic>).cast<double>())
.toList(),
channelMapping: (raw['channelMapping'] as List<dynamic>)
.map((dynamic item) => (item as List<dynamic>).cast<int>())
.toList(),
sensitivity: raw['sensitivity'],
maxSpl: raw['maxSpl'],
minSpl: raw['minSpl'],
directionality: decodeEnum(
AndroidMicrophoneDirectionality.values, raw['directionality'],
defaultValue: AndroidMicrophoneDirectionality.unknown),
))
.toList();
}
My guess is that invokeListMethod
doesn't do casts recursively, each item inside the list must be explicitly converted via .cast()
. I can't fix it right now, but will take a look on the weekend.
I've pushed a fix on the fix/microphone-cast
branch, please let me know if it works.
FYI I plan to release this fix within the next day, so it will be good if you are able to test before then if you want to ensure the next release contains a working fix for you.
This is now published, so I'll close the issue. I can reopen if you later if you find it not working.
First of all, thanks a lot for this great package, I am really a big fan!
While playing around with the
AndroidAudioManager
I noticed that thegetMicrophones()
function throws an exception. I am well aware that it is marked as "UNTESTED". Anyways, it probably makes sense to note some test results here.API level on my device: 30. Flutter:
The error message I receive is:
Minimal example: