Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make media_player hide image it can't load. #208

Merged
merged 3 commits into from Feb 14, 2017

Conversation

andrey-git
Copy link
Contributor

Make media_player hide image it can't load.

Note that it will still try on every state change.

@mention-bot
Copy link

@andrey-git, thanks for your PR! By analyzing the history of the files in this pull request, we identified @balloob, @bjarniivarsson and @armills to be potential reviewers.

@@ -248,8 +248,20 @@

playerObjChanged: function (playerObj) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a second argument to this function that could help with avoiding trying to catch the picture twice: oldPlayerObj. In that case you can avoid doing any image calculation/attr setting if the picture url is the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the backend PR there was a concert that the failure might be temporary. If we cache the URL the image won't come till the next song.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still support allowing the same URL to retry. Otherwise, the implication would be that any temporary interruption blocks retrying, and could lead to confusion, especially when someone is trying to debug a new media platform.

@balloob
Copy link
Member

balloob commented Feb 12, 2017

🐬

Ok to merge when tests pass.

@andrey-git
Copy link
Contributor Author

I don't have write access in this repo.

if (picture) {
this.$.cover.style.backgroundImage = 'url(' + picture + ')';
dummy = document.createElement('IMG');
Copy link
Contributor

@emlove emlove Feb 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should wrap this in an `if (this.$.cover.style.backgroundImage != 'url(' + picture + ')'), or something along those lines, so that once the image loads successfully, it doesn't keep reloading it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that 🔝

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, wouldn't this be cached too?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, yeah, you're right that the image would be cached. We would still be going through the code of creating the IMG element, but that might be inexpensive enough to justify keeping the code simpler.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about having a hidden iron-image in the template? The image src could just be a computed binding to the entity_picture. We can then listen to the loaded and error properties and update the background image when these events fire.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@balloob The image will be cached, so I don't think if is needed here.
@armills What is the advantage of iron-image? It will attached to the dom so might (not sure) affect performance more.
I don't think the code will be more compact.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The advantage would be that we aren't creating an element and registering events on every state change. I also think that as a high-level idea that making use of the polymer features when available will be more stable than writing our own javascript implementations. This instance should be pretty safe, but using polymer as a practice lets take advantage of their compatibility layer for various browsers.

It will probably be a little larger in LOC, but IMO moving the load/error handlers outside of the playerObjChanged handler will make it easier to quickly grok.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registering events is just setting properties, where with polymer it has to propagate through bindings.
I could extract the functions to separate functions here too. I don't think it is important for readability here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with not using iron-image. If we will need this in another place, we should extract this into a util function that returns a promise.

Oh and next time, you can use dummy = new Image();

@emlove
Copy link
Contributor

emlove commented Feb 13, 2017

I like where this is going. This should also make image transitions smoother, since they'll be loaded in the background before changing the card background image, making the switch smooth.

We might want to also consider adding a timeout to clear the background image if onload or onerror haven't triggered in a timely manner (2-5 seconds?), to prevent keeping the stale image visible for too long.

@andrey-git
Copy link
Contributor Author

Timeout added,

@balloob balloob merged commit 7c9c03a into home-assistant:master Feb 14, 2017
@bramkragten bramkragten mentioned this pull request Jan 29, 2020
tkdrob pushed a commit to tkdrob/frontend that referenced this pull request Apr 20, 2021
* Update sensors.md

Update the documentation according to the merged PR: home-assistant/android#530

* Update docs/core/sensors.md

Prevent iOS battery sensor descriptions from being split up.

Co-Authored-By: Tom Brien <TomBrien@users.noreply.github.com>

* Update docs/core/sensors.md

iOS Battery Sensor description merged into top paragraph.

Co-Authored-By: Tom Brien <TomBrien@users.noreply.github.com>

Co-authored-by: Tom Brien <TomBrien@users.noreply.github.com>
@github-actions github-actions bot locked and limited conversation to collaborators Jul 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants