Resolves #193 Source selection support for media_player
This commit is contained in:
parent
da15e880ec
commit
c5960de0be
@ -73,6 +73,7 @@ class MediaPlayerEntity extends Entity {
|
|||||||
MediaPlayerEntity.SUPPORT_SELECT_SOUND_MODE);
|
MediaPlayerEntity.SUPPORT_SELECT_SOUND_MODE);
|
||||||
|
|
||||||
List<String> get soundModeList => getStringListAttributeValue("sound_mode_list");
|
List<String> get soundModeList => getStringListAttributeValue("sound_mode_list");
|
||||||
|
List<String> get sourceList => getStringListAttributeValue("source_list");
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget _buildAdditionalControlsForPage(BuildContext context) {
|
Widget _buildAdditionalControlsForPage(BuildContext context) {
|
||||||
|
@ -256,6 +256,7 @@ class _MediaPlayerControlsState extends State<MediaPlayerControls> {
|
|||||||
double _newVolumeLevel;
|
double _newVolumeLevel;
|
||||||
bool _changedHere = false;
|
bool _changedHere = false;
|
||||||
String _newSoundMode;
|
String _newSoundMode;
|
||||||
|
String _newSource;
|
||||||
|
|
||||||
void _setVolume(double value, String entityId) {
|
void _setVolume(double value, String entityId) {
|
||||||
setState(() {
|
setState(() {
|
||||||
@ -285,6 +286,14 @@ class _MediaPlayerControlsState extends State<MediaPlayerControls> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _setSource(String source, String entityId) {
|
||||||
|
setState(() {
|
||||||
|
_newSource = source;
|
||||||
|
_changedHere = true;
|
||||||
|
eventBus.fire(ServiceCallEvent("media_player", "select_source", entityId, {"source": "$source"}));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final MediaPlayerEntity entity = EntityModel.of(context).entityWrapper.entity;
|
final MediaPlayerEntity entity = EntityModel.of(context).entityWrapper.entity;
|
||||||
@ -372,6 +381,22 @@ class _MediaPlayerControlsState extends State<MediaPlayerControls> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (entity.supportSelectSource && entity.sourceList != null) {
|
||||||
|
if (!_changedHere) {
|
||||||
|
_newSource = entity.attributes["source"];
|
||||||
|
} else {
|
||||||
|
_changedHere = false;
|
||||||
|
}
|
||||||
|
children.add(
|
||||||
|
ModeSelectorWidget(
|
||||||
|
options: entity.sourceList,
|
||||||
|
caption: "Source",
|
||||||
|
value: _newSource,
|
||||||
|
onChange: (value) => _setSource(value, entity.entityId)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return Column(
|
return Column(
|
||||||
children: children,
|
children: children,
|
||||||
|
Reference in New Issue
Block a user