When react-video hls.js plays m3u8 video, there is a delay in switching.

when recat-video hls.js develops a video playback page, m3u8 is loaded,
the video is replayed after updating the resource, but the longer video will play the previous video for a period of time before switching to the new video

HLSSource

    import React, { Component } from "react";
import Hls from "hls.js";

export default class HLSSource extends Component {
  constructor(props, context) {
    super(props, context);
    this.hls = new Hls();
  }

  componentDidMount() {
    // this.setHls()
  }
  componentWillReceiveProps() {
    
  }
  setHls = () => {
    console.log(this.hls)
    const { src, video } = this.props
    if (Hls.isSupported()) {
      this.hls.loadSource(src);
      this.hls.attachMedia(video);
    }
  }
  play = () => {
    const { video } = this.props
    this.hls.on(Hls.Events.MANIFEST_PARSED, () => {
      video.play();
    });
  }
  destroy = () => {
    if (this.hls) {
      this.hls.destroy()
    }
  }
  componentWillUnmount() {
    // destroy hls video source
    if (this.hls) {
      this.hls.destroy()
    }
  }

  render() {
    return (
      <source
        src={this.props.src}
        preload="none"
        type={this.props.type || "application/x-mpegURL"}
      />
    );
  }
}

Player

  change = (lesson) => {
    
        const Player = this.refs.player
        this.setState({
            courseUrl: url
        }, () => {
            this.refs.hlsSource.setHls()
            // resource 
            this.refs.hlsSource.play() 
            // Player.load() 
        })
    }
    render ){
    return(
    <Player
            ref="player"
            playsInline
            autoPlay={false}
            className="video-play"
            startTime={this.state.startTime}>
            <HLSSource
                isVideoChild
                ref="hlsSource"
                src={this.state.courseUrl} />
        </Player>
        )}
Sep.17,2021

recommend a player

dplayer ( http://dplayer.js.org/-sharp/)

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b2b3d0-2b1f8.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b2b3d0-2b1f8.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?