更新src后,videoJS中的视频反应未加载

时间:2017-07-20 01:05:29

标签: javascript reactjs html5-video video.js video-reactjs

我正在使用视频反应(https://video-react.js.org/components/player/),在页面上,它说我可以在更新其来源后使用 1) PostsController POST create assigns the new post to @post Failure/Error: post :create, post: {title: RandomData.random_sentence, body: RandomData.random_paragraph} ArgumentError: unknown keyword: post 。但是我认为这种方法不再受支持了,因为它根本无法工作,而且在用npm下载的源代码中找不到它。

还有其他方法可以做到这一点,还是有人找到了解决方案?这是我的部分代码:

this.refs.player.load()

这没效果。我尝试重命名ref但仍然没有。 div显示但不是玩家。

编辑:刚刚在Player.js组件中找到了这个,但无法弄清楚如何实现它:Player.js component source code

1 个答案:

答案 0 :(得分:1)

this.refs不存在的原因是因为您的代码只是直接触摸DOM而不是使用React生命周期。请按以下方式修改代码

import React from 'react';
import { Player } from 'video-react';

class DisplayVideo extends React.Component {
    render () {
      const { data } = this.props
      return (
        <div className="col-md-4" id="videoRows">
          <div id="myPlayer">
            <Player src={data.val().videoURL} ref={(el) => this.player = el} />
          </div>
        </div>
      )
    }

    componentDidMount () {
      this.player.load()
    }
}