reactjs - How can I detect when video finished playing react? -


since react uses lifecycle methods , virtual dom how can detect when video has finished playing. found question on stackoverflow suggested use componentwillunmount there's no point @ remove video dom, componentwillunmount won't fired...

how can detect when video finished playing react?

use ref callback obtain reference <video dom element when mounts.

<video ref={el => this.videoelement = el}></video> 

combine componentdidmount() add event listener video element. ended event you're looking for.

the ended event fired when playback or streaming has stopped because end of media reached or because no further data available.

componentdidmount() {     this.videoelement.addeventlistener("ended", mycallback); } 

Comments

Popular posts from this blog

service - Android MediaPlayer calls onCompletion before it already finished -

javascript - Training Neural Network to play flappy bird with genetic algorithm - Why can't it learn? -

javascript - Create a stacked percentage column -