-
Notifications
You must be signed in to change notification settings - Fork 7.5k
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
Responsive Sizing #982
Comments
“autoHeight” might be more descriptive. “Responsive” can mean all sorts of things, including calculating width based on height. What we’re talking about here is specifically calculating height based on width, in a typical column-layout. Providing one option is also terser than specifying three:
Poster sizing should be unaffected. |
FWIW, we've been using a variation on the "intrinsic ratio method" with videojs for several months and it's been great. Examples at: We played with keeping things in their native aspect ratio but 4:3 videos were just too massive on wider browser widths, so we lock everything down to 16:9. I'd vote for "aspectRatio" for the config item. Makes the most sense to me. |
Thanks @jgubman, that's interesting to know about 4:3 videos. I agree with @baloneysandwiches that 'responsive' is too vague. I don't love the idea of having both I created a number of user stories and added them to the body of the issue. It at least helped me wrap my mind around the full problem set better. There's essentially two things we need to know from the user: Q1. Do you have a specific aspect ratio you want? An alternative option I'm consider is |
I find the use case for calculating width based on fixed height to be somewhat obscure, given current layout patterns in the wild, but since the video element supports that, it agree would be nice to address as well for future layout flexibility. “aspectRatio” has the advantage of neutrally addressing the fixed height, flexible width use case. I think it would great if there were a way to avoid the two-layout-modes thing. That’s tricky. I think what emerges from the above range of use cases is that “responsive” should not be a specialized mode, but the norm. Can the fixed width cases can be built around a default “fluid” code structure? For example in the “fixed height, known aspect ratio” use case:
It would be ideal to set a fixed CSS width, based on a little algebra, and still use The big obstacle to this, as you point out, is that percentage padding refers to the parent. So if you want a fixed dimension, you need another wrapping parent element to apply the style too. This was the hiccup all the way back in Thierry’s original demo. Yeah, it’s ugly, div-itis, etc, but it simplifies the problem greatly. Are you willing to consider an additional default wrapping div? |
It would make things a little easier if we could default to fluid. Then any time width/height was set you could drop out of fluid mode. But part of the goal of video.js is to work just like the video element. I made this jsbin earlier to see exactly how the element works by default. It would also be a pretty big change from existing versions, so we'd probably have to delay the change until 5.0. I'd definitely prefer to avoid adding another wrapper div, especially if that would be the default. |
One other note is that a fluid width video isn't exactly the best for performance and quality. Increasing or decreasing the size of the video from its actual dimensions makes the decoder do extra work and degrades the quality. This happens all the time with full screen video, but still, it's best to display the video at its actual size, which is what the video element does by default. If we were to default to fluid, I don't know if there's a good way to auto set the width/height from the metadata. Maybe width=auto height=auto. That's similar to what we have now, and it's not great. |
I agree that things look best (and perform best) at their encoded size. That’s a good pointer to put in the docs. Also, it should inform how the “null options object” case is handled:
Note that this doesn’t mean setting up “auto” keywords for width and height. I agree that’s bad to expose externally. If you’re willing to entertain the notion of an extra div, all of your use cases in the initial comment can be handled using intrinsic ratios. I can type up a full rundown if it’s helpful. I agree it’s painful from a markup perspective, but it seems possibly less painful than tracking down and patching every possible bug involving switching back and forth between broadly conceived fluid and fixed modes. That frankly sounds like a nightmare to write and maintain. There is one tricky use case. I’ll call it “the stretch”: videojs('id', { aspectRatio: '16:9’, width: ‘500px’; height: ‘500px’ }) This genuinely requires a “fixed” mode, because negative height or negative padding would be needed to compensate in certain cases, and those values aren’t allowed. While legitimate, this use case seems to be nicely isolated. Maybe add a “stretch” class when all three options are supplied and the math doesn't line up? |
Is stretch similar to There might be an opportunity to avoid the second div and instead set the tech element to position:relative, and add the padding height to that, but as is that would create a flash of zero height when switching between techs (e.g. playing ads). And so far we've relied on everything being position:absolute in the player, so that would take some serious testing. Defaulting to fluid is too big of a change and detraction from the spec to do before 5.0, and I'd like to get something in sooner, so I could see this going in two steps either way.
If there's potential for defaulting to fluid in the future, then aspectRatio might be the better option name than fluid. But in the first step we'd still be better off assuming that if the user uses aspectRatio that they want a fluid layout support. With that being the case, I think the user stories in the issue body hold up and we could start working on those. |
“Is stretch similar to background: cover and the BigVideo.js example?” “Stretch” and “cover” are completely different use cases. Stretch shows all of the video, at a tweaked proportion. Kind of like when you resize an img in photoshop with the “constrain proportions” checkbox unchecked. You get the same thing in a browser for an img when you write:
(The height will stay fixed at 500px, and not bump up to 1000px unless you add in height: Cover (at least in <a href-“http://www.w3.org/TR/css3-background/#the-background-size”>CSS background-size) is when the image maintains its aspect ratio, but the image grows so that the container is completely covered by image. Part of the image is cropped, not shown, either at the top/bottom or at the sides, never both. The logic for this is actually fairly simple:
and set the container CSS to “There might be an opportunity to avoid the second div and instead set the tech element to position:relative, and add the padding height to that." That won’t work as you’ve described it. The intrinsic ratios ” but as is that would create a flash of zero height when switching between techs (e.g. playing ads).” Well, you could write it so that for consecutive videos, the previous video's "Defaulting to fluid is too big of a change and detraction from the spec." Well, as far as the spec, it’s actually closer to how the video element behaves. Also, I’m not suggesting defaulting to fluid per se, I’m suggesting defaulting to any fixed width supplied by the author, and if no width or height is supplied by the author, defaulting to the width (and thus also height) in metadata. That isn’t exactly fluid, it’s actually fixed, at least until author CSS (e.g. container |
Just curious what the status is with this feature. Would be very useful. |
Just haven't had a chance to implement it yet. Feel free to try if you're interested. |
A possible implementation (not by me): http://coolestguidesontheplanet.com/videodrome/videojs/
|
+1 This would really be a great feature to have! |
I would love to see this happen. |
Still working on this one, but the implementation @ernsheong referenced is a great starting point for something looking for a stopgap solution. |
For anyone else that's implementing the workaround @ernsheong mentioned, you'll need to absolutely position the poster image in order to see it. It's currently set to fill 100% of the parent element, which doesn't work when using this workaround. .vjs-poster {
position: absolute;
top: 0;
bottom: 0;
right: 0;
left: 0;
} |
+1 |
+1 |
Thanks for the feedback, everyone. This definitely something we're targeting to fix by 5.0 (at latest). I don't want to lock the issue because feedback on implementation would be fantastic, but no more +1s are needed at this point. |
We were able to factor in the height of the browser window by setting the width of an outer container using vh units (width: 124vh;). You can see a demo on our video player pages: |
I see that it works, but I am sorry I am kind of a novice with this sort of this and the source code of your site is completely overwhelming to me lol. |
vh is a viewport height unit, here are a few good overviews: http://css-tricks.com/viewport-sized-typography/ http://css-tricks.com/viewport-sized-typography/ http://demosthenes.info/blog/660/Using-vw-and-vh-Measurements-In-Modern-Site-Design http://demosthenes.info/blog/660/Using-vw-and-vh-Measurements-In-Modern-Site-Design
|
If I create "div { height: 50vh; } code, i end up with this If I try putting height: 50vh; in the .wrapper or .videocontent, nothing happens, also if i try doing it inline in the still nothing happens
Like I said, I am pretty dumb with this stuff, thank you guys for trying to help. |
Don’t wrap a div w/ height: 50vh, instead keep the settings you already have in .videocontent and add a "width: 125vh;" declaration. Also, if you need help w/ CSS, you should take the discussion to stackoverflow or somewhere. The github issues isn’t a very appropriate place to have this discussion.
|
Sorry, I thought it was relevant to the responsive sizing discussion. |
I have tried using the CSS only solution mentioned by @j4k3 on Aug 2. In general, this worked well for me. However, the aspect ratio was somehow thrown off just enough to create extra "space" above/below the video. Could not figure out how to fix that. The CSS solution is basically the same as outlined in the css-tricks article (as well as other places): Fluid Width Video. In there they put
Just posting in case someone else runs into this problem... |
this is css u can use for responsive body .video-js .vjs-tech { |
I would say that CSS transform is the best implementation choice. Ancient browsers are pre-mobile, and we usually want responsive for mobile environment. I would rather develop a good rock-solid solution using CSS transform, and offer a best-effort solution fallback for stone age browsers. |
hd = 16:9, sd=4:3
http://stackoverflow.com/a/24413783 (Adapted from: http://css-tricks.com/NetMag/FluidWidthVideo/Article-FluidWidthVideo.php) That css code works great: http://rmshow.tk/ (example video.js resizing) |
Responsive Sizing #982 I have tried using the CSS only solution mentioned by @j4k3 on Aug 2. In general, this worked well for me. However, the aspect ratio was somehow thrown off just enough to create extra "space" above/below the video. Could not figure out how to fix that. The CSS solution is basically the same as outlined in the css-tricks article (as well as other places): Fluid Width Video. In there they put height: 0; in the wrapper, which in this case is the .video-js:afterblock. Adding this closed up the extra space. .video-js { width:100%!important; height: auto!important; } Example: https://gist.github.com/odev79/6f30981e24123ad7df3c |
Closed thanks to #1952. |
To save people from reading this enormous thread, can something be added to the README that explains how to implement fluid/responsive sizing? |
@SimonEast wanna help put one together? |
If base video is 1903x965 ... var windowWidth = $(window).innerWidth(); |
yes @SimonEast : I am missing some real documentation. There isn't a chapter on how to use data-setup properly and what options are available. I love the performance of videojs but getting the videos to stay within the my containers is becoming a hassle |
Not really documentation but I wrote a bit about fluid mode here: http://videojs.github.io/blog/Video-js-5-s-fluid-mode-and-playlist-picker/ |
I tried another player but I'm going to give video.js another attempt. Hope I can get it playing nicely |
What am I missing? I feel like such a noob atm. I'm including screenshots of the code and result between videojs with & without fluid. The html
The css for ".screen"
|
Do you include css of video-js, for example http://vjs.zencdn.net/5.10.7/video-js.min.css ? |
I'm almost sad that I did include it ;) |
A friend came to the rescue. Hopefully I will have time soon to add it to your codebase as a setup option "responsive : true". Init:
css:
|
you probably also want to call |
Responsive sizing is when the player can dynamically change size to fit its container while maintaining the desired aspect ratio. This should be a feature built into video.js and we need to find out the right way to add it. (it's currently possible with additional work or outside libs)
To finish
Related issues: #771, #359, #384, #925, #983
Also see the intrinsic ratio example from @baloneysandwiches
Related Links:
http://alistapart.com/article/creating-intrinsic-ratios-for-video/
The intrinsic ratio method seems like the best approach. In order to make that happen, we need to allow the user to supply the ratio some how. Some potential options:
(specific naming TBD)
Video.js would essentially have 2 layout modes, fixed and responsive, and we would probably apply a different class of styles to the player div depending on which was needed.
Additional considerations
User Stories Draft
Not sure if all of these are valid, but providing possible solutions for each based on the aspectRatio/autoHeight setting.
The text was updated successfully, but these errors were encountered: