javascript - video Label Video playback - Stack Overflow

data(element: any, index: number) {const m3u8 = this.arrItem[index].name;const videoSrc = `http:local

data(element: any, index: number) {
       const m3u8 = this.arrItem[index].name;
       const videoSrc = `http://localhost:8080/video/data/${m3u8}`;

      if (Hls.isSupported()) {
      let hls = new Hls();
      hls.loadSource(videoSrc);
      hls.attachMedia(element);

      hls.on(Hls.Events.MANIFEST_PARSED, function () {
        console.log("HLS 加载成功");
        element.muted = true;
        element.play().catch(err => console.warn("自动播放被阻止:", err));
      });

      hls.on(Hls.Events.ERROR, function (event, data) {
        console.error("HLS 加载错误:", data);
      });

      hls.on(Hls.Events.FRAG_LOADED, function (event, data) {
        console.log("加载 TS 片段:", data.frag.url);
      });

    } else if (element.canPlayType('application/vnd.apple.mpegurl')) {
      element.src = videoSrc;
      element.addEventListener('loadedmetadata', function () {
        element.muted = true;
        element.play();
      });
    } else {
      console.error("当前浏览器不支持 HLS");
    }
  }



 ngAfterViewInit(): void {
    this.videoElements.changes.subscribe(() => {
      this.videoElements.forEach((video, index) => {
        this.data(video.nativeElement, index);
      });
    });
  }`enter code here`
}


enter image description here Why is it that my videos won't play,I use the same code, why can Youdao video play forced back ts files, and Youdao can not play, so my first ts files are 200, and my m3u8 also requested back data?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744310856a4567939.html

相关推荐

  • javascript - video Label Video playback - Stack Overflow

    data(element: any, index: number) {const m3u8 = this.arrItem[index].name;const videoSrc = `http:local

    7天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信