Update state when video ends in MediaPlayer

The MediaPlayer receives the handleAutoplay method as a prop from PlayMedia. We will update the listener code for the onEnded event to execute this method only when the loop is set to false for the current video.

mern-mediastream/client/media/MediaPlayer.js:

onEnded = () => {  if(this.state.loop){    this.setState({ playing: true})  }else{    this.props.handleAutoplay(() => {                              this.setState({ ended: true,                                                 playing: false })                            })     }}

A callback function is passed to the handleAutoplay method, in order to set playing to false and render the replay icon button instead of the play or pause icon button, after it is determined in PlayMedia that the autoplay has not been set or that the related media list is empty. ...

Get Full-Stack React Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.