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

Apply aspect ratio from video #211

Closed
wmertens opened this issue Jun 30, 2017 · 7 comments
Closed

Apply aspect ratio from video #211

wmertens opened this issue Jun 30, 2017 · 7 comments

Comments

@wmertens
Copy link

Related to #145: It would be nice if you could tell the player to use the native video aspect ratio.

Once the video is available, it seems that the readonly props videoHeight and videoWidth should be there, and then by measuring the ReactPlayer's parent element dimensions, the <video> can be sized, or for smooth responsiveness the padding-top trick could be used to force a height if the width is a css-fixed value.

@cookpete
Copy link
Owner

cookpete commented Jul 3, 2017

Assuming you are using FilePlayer, you should be able to set width and height of the wrapper and the <video> element to auto (or anything you like) like so:

<ReactPlayer
  url='http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4'
  playing
  width='auto'
  height='auto'
  fileConfig={{ attributes: { style: { 
    display: 'block', 
    width: 'auto', 
    height: 'auto' 
  }}}}
/>

jsFiddle of the above

This does seems a bit hacky so perhaps the width and height of the <video> should be automatically set to auto if the top level width and height props are auto. Then the fileConfig hack would be unnecessary.

@0xjjpa
Copy link

0xjjpa commented Nov 13, 2017

@cookpete Just wanted to mention that none of these solutions are working anymore. Checked both the fiddles from here and #145 and they are not displaying the videos at all. Maybe a problem with an updated version?

@cookpete
Copy link
Owner

@jjperezaguinaga Yeah all React fiddles made from the old base fiddle (before react@16 came along) are now broken, as they've changed how the files work. The old React base jsFiddle used react-with-addons.js that now does not exist in v16.

Here's an updated fiddle (note how the fileConfig is no longer necessary since b59d251).

@0xjjpa
Copy link

0xjjpa commented Nov 17, 2017

Great, looks really nice! And if I had one dollar for every jsfiddle that I've broken over the past years 🙈

@sedubois
Copy link

I tried this with react-player@1.0.0-beta.5 and a Vimeo URL with no success. What is the proper way to have responsive Vimeo sizing?

@cookpete
Copy link
Owner

I tried this with react-player@1.0.0-beta.5 and a Vimeo URL with no success. What is the proper way to have responsive Vimeo sizing?

@sedubois The width='auto' height='auto' trick will only work when playing files, as the height of a <video> element is determined by the height of the video itself, whereas the height of an iframe is determined by the height given by the parent window.

If you know the aspect ratio you want for the video, you can use a responsive wrapper as described here.

The jsFiddle example there is also broken thanks to react@16, so here is an updated one.

@sedubois
Copy link

Thanks for the quick reply! CSS is dark magic for me, but I got something working:

export default ({ url }) => (
  <div
    css={{
      display: `flex`,
      minHeight: `100vh`,
      background: `black`,
    }}
  >
    <div
      css={{
        width: `90%`,
        maxWidth: 1000,
        margin: `auto`,
      }}
    >
      <div
        css={{
          position: `relative`,
          paddingTop: `56.25%`,
        }}
      >
        <ReactPlayer
          url={url}
          width="100%"
          height="100%"
          css={{
            position: `absolute`,
            top: 0,
            left: 0,
          }}
        />
      </div>
    </div>
  </div>
)

david-hub024 pushed a commit to david-hub024/React_VideoPlayer that referenced this issue Dec 23, 2018
david-hub024 pushed a commit to david-hub024/React_VideoPlayer that referenced this issue May 23, 2020
albanqoku added a commit to albanqoku/react-player that referenced this issue Feb 24, 2021
Webmaster1116 added a commit to Webmaster1116/video-player that referenced this issue May 20, 2021
webmiraclepro added a commit to webmiraclepro/video-player that referenced this issue Sep 9, 2022
philip-luther added a commit to philip-luther/react-player that referenced this issue Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants