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
Conversation
@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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
🐬 Ok to merge when tests pass. |
I don't have write access in this repo. |
if (picture) { | ||
this.$.cover.style.backgroundImage = 'url(' + picture + ')'; | ||
dummy = document.createElement('IMG'); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that 🔝
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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();
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. |
Timeout added, |
* 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>
Make media_player hide image it can't load.
Note that it will still try on every state change.