视频播放完毕后,我正在尝试自动关闭灯箱。
onEnded
属性在 99.99% 的时间里都很好用,但有时它不会触发回调。所以我尝试使用onDuration
.
上述错误发生在设置为的回调中onDuration
。控制台打印持续时间很好,但我不确定为什么它无法识别以下方法并抛出错误。this.props.lightBoxHandler(this.props.entry.type);
renderEntry() {
if (this.props.entry.type === "photo") {
this.disableLightbox();
return <img alt={Math.random()} src={this.props.entry.entry} onClick={ () => this.props.lightBoxHandler(this.props.entry.type)} />
}
if (this.props.entry.type === "video") {
return <ReactPlayer
url={this.props.entry.entry}
className='react-player'
playing={true}
width='100%'
height='100%'
onEnded={() => this.props.lightBoxHandler(this.props.entry.type)}
onDuration={(duration) => {
console.log("Duration " + duration);
setTimeout(function () {
this.props.lightBoxHandler(this.props.entry.type);
}, duration*1000) }}
/>
}
}
render() {
let classList = this.props.entry.is === true ? "lightbox-wrapper active" : "lightbox-wrapper";
return (
<React.Fragment>
<div className={classList}>
{this.renderEntry()}
</div>
</React.Fragment>
);
}