Autoplaying related media
We will complete the autoplay functionality discussed earlier by adding a toggle in PlayMedia
, and implementing the handleAutoplay
method, which needs to be called when a video ends, in the MediaPlayer
component.
Toggling autoplay
Besides letting the user set autoplay, the toggle will also indicate whether it is currently set or not:
For the autoplay toggle, we will use a Material-UI
Switch
component along with a FormControlLabel
, and add it to the PlayMedia
component over the RelatedMedia
component to be rendered only when there are media in the related media list.
mern-mediastream/client/media/PlayMedia.js
:
<FormControlLabel control={ <Switch checked={this.state.autoPlay} onChange={this.handleChange} color="primary" /> } label={this.state.autoPlay? 'Autoplay ON':'Autoplay OFF'} />
To handle the change to the toggle and reflect it in the state's autoplay
value, we will use...