feat: populate audio output device menu and group by backend

This commit is contained in:
edde746
2026-02-16 21:56:22 +01:00
parent 9d04833b3e
commit 29f5dc00c4
3 changed files with 118 additions and 17 deletions
+36 -1
View File
@@ -109,7 +109,7 @@ abstract class PlayerBase with PlayerStreamControllersMixin implements Player {
void _handleEvent(dynamic event) {
if (event is List && event.length == 2) {
final name = _propIdToName[event[0]];
final name = _propIdToName[event[0] as int];
if (name != null) {
handlePropertyChange(name, event[1]);
}
@@ -217,6 +217,41 @@ abstract class PlayerBase with PlayerStreamControllersMixin implements Player {
case 'sid':
updateSelectedSubtitleTrack(value);
break;
case 'audio-device-list':
List? deviceList;
if (value is List) {
deviceList = value;
} else if (value is String && value.isNotEmpty) {
try {
final parsed = jsonDecode(value);
if (parsed is List) deviceList = parsed;
} catch (_) {}
}
if (deviceList != null) {
final devices = deviceList
.whereType<Map>()
.map((d) => AudioDevice(
name: d['name'] as String? ?? '',
description: d['description'] as String? ?? '',
))
.toList();
_state = _state.copyWith(audioDevices: devices);
audioDevicesController.add(devices);
}
break;
case 'audio-device':
if (value is String && value.isNotEmpty) {
final device = _state.audioDevices.cast<AudioDevice?>().firstWhere(
(d) => d?.name == value,
orElse: () => AudioDevice(name: value),
) ??
AudioDevice(name: value);
_state = _state.copyWith(audioDevice: device);
audioDeviceController.add(device);
}
break;
}
}