javascriptcssreactjsreact-player

Can't resize React-Player Video


Can't resize React-Player Video. I change the width to any number and the video stays unchanged. I am trying to optimize it for computer view and then add breakpoints to resize for smaller screens like phones.

Bellow is the file where I render the React-Player video inside a on which I apply the desired height and width I would like my react-player video to adopt.

import React, { useContext, useEffect, useState } from 'react'
import { makeStyles } from '@material-ui/core/styles'
import Modal from '@material-ui/core/Modal'
import { MovieContext } from './MovieContext'
import ReactPlayer from 'react-player'
import { getTrailer } from '../utils/movieDB'
// potential of adding controls
// import { Slider, Direction } from 'react-player-controls'
//slider to be implemented
//https://www.npmjs.com/package/react-player-controls#playericon-

const useStyles = makeStyles((theme) => ({
  video: {
    width: 'auto',
    height: 'auto',
    top: '25%',
    right: '25%',
    position: 'fixed',
    [theme.breakpoints.down('xs')]: {},
  },
}))

const styles = {
  player: {
    width: '300px',
  },
}

export default function SimpleModal({ open }) {
  const classes = useStyles(),
    //receives movie from Home > DisplayCard > MovieContext
    { setOpenTrailer, movie, setMovie } = useContext(MovieContext),
    [trailer, setTrailer] = useState(),
    [key, setKey] = useState(),
    [modalStyle] = useState()

  useEffect(() => {
    if (movie) {
      getTrailer(movie).then((data) => {
        setKey(data.videos.results[0].key)
        setTrailer(data)
      })
    }
  }, [movie])

  const handleOpen = () => {
    setOpenTrailer(true)
  }

  const handleClose = () => {
    setOpenTrailer(false)
    setMovie(undefined)
    setTrailer(undefined)
    setKey(undefined)
  }

  const renderVideo = (
    <>
      {key && (
        <div className={classes.video}>
          <ReactPlayer style={styles.player} url={`https://www.youtube.com/watch?v=${key}`} />
        </div>
      )}
    </>
  )

  return (
    <div>
      <Modal
        open={open || false}
        onClose={handleClose}
        aria-labelledby="simple-modal-title"
        aria-describedby="simple-modal-description"
      >
        {renderVideo}
      </Modal>
    </div>
  )
}

Which is the proper way to set the dimensions on a react-player object?


Solution

  • Using the width and height props as such:

    <ReactPlayer
     width={“300px”}
     url={`https://www.youtube.com/watch?v=${key}`} />