Sound mode support for media player

This commit is contained in:
Yegor Vialov
2018-11-23 14:11:34 +02:00
parent efbe33f4e3
commit da15e880ec
7 changed files with 40 additions and 13 deletions

View File

@ -255,6 +255,7 @@ class _MediaPlayerControlsState extends State<MediaPlayerControls> {
double _newVolumeLevel;
bool _changedHere = false;
String _newSoundMode;
void _setVolume(double value, String entityId) {
setState(() {
@ -276,6 +277,14 @@ class _MediaPlayerControlsState extends State<MediaPlayerControls> {
eventBus.fire(ServiceCallEvent("media_player", "volume_down", entityId, null));
}
void _setSoundMode(String value, String entityId) {
setState(() {
_newSoundMode = value;
_changedHere = true;
eventBus.fire(ServiceCallEvent("media_player", "select_sound_mode", entityId, {"sound_mode": "$value"}));
});
}
@override
Widget build(BuildContext context) {
final MediaPlayerEntity entity = EntityModel.of(context).entityWrapper.entity;
@ -347,6 +356,22 @@ class _MediaPlayerControlsState extends State<MediaPlayerControls> {
));
}
if (entity.supportSelectSoundMode && entity.soundModeList != null) {
if (!_changedHere) {
_newSoundMode = entity.attributes["sound_mode"];
} else {
_changedHere = false;
}
children.add(
ModeSelectorWidget(
options: entity.soundModeList,
caption: "Sound mode",
value: _newSoundMode,
onChange: (value) => _setSoundMode(value, entity.entityId)
)
);
}
}
return Column(
children: children,