【发布时间】:2018-11-09 12:55:10
【问题描述】:
我正在尝试将我的组件修复为从网络摄像头流式传输数据。它成功渲染并成功访问网络摄像头。但我不知道为什么视频标签不播放任何东西。如何解决这个问题?我错过了什么?
export class WebcamStream extends React.Component {
constructor(props) {
super(props);
this.state = {
src: null
}
this.videoRef = React.createRef()
}
componentDidMount() {
// getting access to webcam
navigator.mediaDevices
.getUserMedia({video: true})
.then(stream => this.setState({src: stream}))
.catch(console.log);
}
render() {
return <video id={this.props.id}
ref={() => this.videoRef.srcObject = this.state.src}
width={this.props.width}
height={this.props.height}
autoPlay="autoplay"
title={this.props.title}></video>
}
}
【问题讨论】:
标签: reactjs html5-video webcam