Javascript 更新src后未加载videoJS中的视频响应
我正在使用Video react(),在页面上,它说一旦我更新了它的源代码,我就可以使用Javascript 更新src后未加载videoJS中的视频响应,javascript,reactjs,html5-video,video.js,video-reactjs,Javascript,Reactjs,Html5 Video,Video.js,Video Reactjs,我正在使用Video react(),在页面上,它说一旦我更新了它的源代码,我就可以使用this.refs.player.load()。但我认为该方法不再受支持,因为它根本不起作用,而且我在使用npm下载的源代码中找不到它 是否有其他方法可以做到这一点,或者是否有人找到了解决方案?这是我的部分代码: var videoRow = document.createElement("div"); videoRow.className = 'col
this.refs.player.load()。但我认为该方法不再受支持,因为它根本不起作用,而且我在使用npm下载的源代码中找不到它
是否有其他方法可以做到这一点,或者是否有人找到了解决方案?这是我的部分代码:
var videoRow = document.createElement("div");
videoRow.className = 'col-md-4';
videoRow.setAttribute("id", "videoRows");
//create the myPlayer div which will contain the Player.
var myPlayerDiv = document.createElement("div");
myPlayerDiv.setAttribute("id", "myPlayer");
//create my player with the information from the attributes.
var videoPlayer = document.createElementNS('', 'Player');
videoPlayer.setAttribute("src", data.val().videoURL);
videoPlayer.setAttribute("ref","player");
myPlayerDiv.appendChild(videoPlayer);
videoRow.appendChild(myPlayerDiv);
document.getElementById('videoList').appendChild(videoRow);
this.refs.player.load();
这是行不通的。我尝试重新命名ref,但仍然没有任何结果。裁判出现了,但球员没有出现
Edit:刚刚在Player.js组件中找到了它,但不知道如何实现它:之所以不存在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()
}
}
从“React”导入React;
从“视频反应”导入{Player};
类DisplayVideo扩展了React.Component{
渲染(){
const{data}=this.props
返回(
this.player=el}/>
)
}
组件安装(){
this.player.load()
}
}