Hi,
Is it possible to make the <ReactPlayer> width responsive?
For example to inherit the width of the div or td in which is placed?
Thanks
You should be able to pass 100% to the width and height props and it will fill it's container. If you want responsive width and aspect ratio, do something like this:
.wrapper {
position: relative;
padding-top: 56.25% /* Player ratio: 100 / (1280 / 720) */
}
.player {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
}
<div className='wrapper'>
<ReactPlayer
className='player'
playing
url={...}
width='100%'
height='100%'
/>
</div>
Also see example jsFiddle.
Thanks!
This would be very helpful to include in the README.
This would be very helpful to include in the README.
Nearly a year late but it's finally in there: https://github.com/CookPete/react-player#responsive-player 😞
This does not work for vertical videos. Is there a solution where the padding-top is not static and it is calculated from the video dimension?
@vicentel89 Same issue here !
It depends what type of video you are playing.
If you are playing a raw video file, just set width='100%' height='auto' and the video element will fill the container and retain aspect ratio (the same way an img does). Example: https://jsfiddle.net/f5kxarjq/
If you are playing something that uses an iframe (youtube, facebook etc), they have no knowledge of the aspect ratio of the video, so a _dynamic_ aspect ratio is not possible.
If you know the aspect ratio of your vertical video, this trick still works – just reverse the numbers. So the padding-top line would become:
padding-top: 177.78% /* Player ratio: 100 / (720 / 1280) */`
Most helpful comment
You should be able to pass
100%to thewidthandheightprops and it will fill it's container. If you want responsive width and aspect ratio, do something like this: