-
Notifications
You must be signed in to change notification settings - Fork 82
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
Experimenting with an aspect-ratio attribute #66
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/mux/media-chrome/HYBJXE2dWNNj5nK9v7k65Wj6EtXX |
Are you trying to enforce an aspect ratio that's different from the If the former, your general direction makes sense to me, though you may want to explore https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet as a "cleaner" way to dynamically add/update StyleSheets and CSS rules (assuming we don't want to simply add If the latter, I think that's part of a larger CSS cleanup effort. For that particular case, we should be able to do something similar to what I did in |
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.
Cooooooool. Does this work? I thought it required two elements and this is just using media-container.
https://alistapart.com/article/creating-intrinsic-ratios-for-video/
src/js/media-container.js
Outdated
@@ -30,11 +30,15 @@ template.innerHTML = ` | |||
} | |||
|
|||
/* Video specific styles */ | |||
:host(:not([audio])) { | |||
:host(:not([audio]):not([aspect-ratio])) { |
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.
Do we need this or can we just let the later rule override this one? i.e. can you add height: auto
with width:100%
below?
height: 480px; | ||
width: 720px; | ||
} | ||
|
||
:host([aspect-ratio]) { | ||
width: 100%; |
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.
Doesn't this need a height of 0px to work? Does that break the inner layout within the media container? For example the control bar is not absolutely positioned, so I'd assume it forces some height in addition to the padding creating the ratio.
src/js/media-container.js
Outdated
updateAspectRatio(ratioString) { | ||
const [width, height] = ratioString.split(':'); | ||
|
||
const styleEl = this.shadow.querySelector('style.aspect-ratio'); |
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.
this.shadow
needs to be this.shadowRoot
.
Ok addressed the feedback, but yes, this seems to work great where I've tested it! Keep in mind the assumption here is that you're wrapping this in an element that's controlling width.
It's not necessarily different from the src, but it's more importantly just what the developer specifies. The issue with relying on source is that it's virtually impossible to avoid a weird resize after the file metadata kicks in, so in practice I think that's rarely what folks want. Allowing for a specified aspect ratio allows for people to either directly specify the aspect ratio based on what's in their CMS to avoid a flash, or just have a predefined fluid aspect ratio regardless of the source for better predictability in the layout. I did take a look at CSSStyleSheet but it seemed like support was still sketch enough that I didn't know if we should be relying on it. Is that just a bad assumption? |
I think I understand why this works now. |
I don't know what you're talking about, that looks flawless to me. I need to do some more cross-browser testing anyway, but I'll see if I can make this feel a little cleaner. But also the general responsiveness of the control bar gets pretty wonky. I think we're going to want to make sure we've got some good default stories over responsiveness (or as good as we can given the flexibility). @cjpillsbury Any other thoughts re: |
Unless I'm missing something, we should be able to use it, since we will just be relying on insertRule and deleteRule for the modifications. We used the JS APIs years ago for another widely used player. |
Not sure if we'd want to resolve this in this PR, but we probably should also be applying these rules to the |
@cjpillsbury let's say we wanted to merge this. What sizing changes have happened since this or should happen before this? Or can we get this updated and move forward with it? |
@cjpillsbury last mentioned this PR could be closed if I recall correctly, the solution is documented here: I'm trying to figure out how to best do this in |
Awesome. Let's give @mmcc a minute to review and make sure this lines up with what he was thinking, or close it in a week otherwise. |
I ran into issues trying to use
media-chrome
in a responsive environment and found myself hacking around the same responsive workflow each time. Instead of offloading all that work to individuals, we can take care of that directly inmedia-container
by allowing anaspect-ratio
attribute.This probably needs some more defensiveness, but wanted to go ahead and open it up to get feedback on the approach.