为了账号安全,请及时绑定邮箱和手机立即绑定

无法调整 React-Player 视频大小

无法调整 React-Player 视频大小

小怪兽爱吃肉 2023-08-24 10:28:10
无法调整 React-Player 视频的大小。我将宽度更改为任意数字,视频保持不变。我正在尝试针对计算机视图对其进行优化,然后添加断点以针对手机等较小屏幕调整大小。下面是我在其中渲染 React-Player 视频的文件,我在其中应用了我希望采用的 React-Player 视频所需的高度和宽度。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>  )}在反应玩家对象上设置尺寸的正确方法是什么?
查看完整描述

2 回答

?
忽然笑

TA贡献1806条经验 获得超5个赞

使用 width 和 height 属性:


<ReactPlayer

 width={“300px”}

 url={`https://www.youtube.com/watch?v=${key}`} />


查看完整回答
反对 回复 2023-08-24
?
扬帆大鱼

TA贡献1799条经验 获得超9个赞

这段代码来自react-player库。这使我的视频具有响应能力

它来自: https: //github.com/cookpete/react-player

class ResponsivePlayer extends Component {

  render () {

    return (

      <div className='player-wrapper'>

        <ReactPlayer

          className='react-player'

          url='https://www.youtube.com/watch?v=ysz5S6PUM-U'

          width='100%'

          height='100%'

        />

      </div>

    )

  }

}

----- CSS ------


.player-wrapper {

  position: relative;

  padding-top: 56.25% /* Player ratio: 100 / (1280 / 720) */

}


.react-player {

  position: absolute;

  top: 0;

  left: 0;

}


查看完整回答
反对 回复 2023-08-24
  • 2 回答
  • 0 关注
  • 202 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信