I am trying to auto close the lightbox, once the video is finished playing.
onEnded
attribute worked great 99.99% of time, but sometimes it's not firing callback. So I tried to use onDuration
.
Above error occurs in the callback set to onDuration
. Console prints duration fine but I am not sure why it can't identify following method and throwing error. 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>
);
}