flv.js icon indicating copy to clipboard operation
flv.js copied to clipboard

Failed to read the 'buffered' property from 'SourceBuffer': This SourceBuffer has been removed from the parent media source.

Open supphia opened this issue 2 years ago • 15 comments

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch [email protected] for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/flv.js/src/core/mse-controller.js b/node_modules/flv.js/src/core/mse-controller.js
index 7974940..a2bec2c 100644
--- a/node_modules/flv.js/src/core/mse-controller.js
+++ b/node_modules/flv.js/src/core/mse-controller.js
@@ -223,6 +223,9 @@ class MSEController {
     }
 
     appendMediaSegment(mediaSegment) {
+        if (!this._mediaSource || this._mediaSource.readyState !== 'open') {
+            return;
+        }
         let ms = mediaSegment;
         this._pendingSegments[ms.type].push(ms);
 
@@ -323,6 +326,9 @@ class MSEController {
     }
 
     _needCleanupSourceBuffer() {
+        if (!this._mediaSource || this._mediaSource.readyState !== 'open') {
+            return;
+        }
         if (!this._config.autoCleanupSourceBuffer) {
             return false;
         }
@@ -333,7 +339,7 @@ class MSEController {
             let sb = this._sourceBuffers[type];
             if (sb) {
                 let buffered = sb.buffered;
![WeChat57c38a1d8eac9dd10281c893575162d8](https://user-images.githubusercontent.com/30256650/127122270-7121f178-f11c-4ba6-b3da-60b31d43c7e0.png)

-                if (buffered.length >= 1) {
+                if (buffered && buffered.length >= 1) {
                     if (currentTime - buffered.start(0) >= this._config.autoCleanupMaxBackwardDuration) {
                         return true;
                     }

This issue body was partially generated by patch-package.

supphia avatar Jul 27 '21 08:07 supphia

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch [email protected] for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/flv.js/src/core/mse-controller.js b/node_modules/flv.js/src/core/mse-controller.js
index 7974940..a2bec2c 100644
--- a/node_modules/flv.js/src/core/mse-controller.js
+++ b/node_modules/flv.js/src/core/mse-controller.js
@@ -223,6 +223,9 @@ class MSEController {
     }
 
     appendMediaSegment(mediaSegment) {
+        if (!this._mediaSource || this._mediaSource.readyState !== 'open') {
+            return;
+        }
         let ms = mediaSegment;
         this._pendingSegments[ms.type].push(ms);
 
@@ -323,6 +326,9 @@ class MSEController {
     }
 
     _needCleanupSourceBuffer() {
+        if (!this._mediaSource || this._mediaSource.readyState !== 'open') {
+            return;
+        }
         if (!this._config.autoCleanupSourceBuffer) {
             return false;
         }
@@ -333,7 +339,7 @@ class MSEController {
             let sb = this._sourceBuffers[type];
             if (sb) {
                 let buffered = sb.buffered;
![WeChat57c38a1d8eac9dd10281c893575162d8](https://user-images.githubusercontent.com/30256650/127122270-7121f178-f11c-4ba6-b3da-60b31d43c7e0.png)

-                if (buffered.length >= 1) {
+                if (buffered && buffered.length >= 1) {
                     if (currentTime - buffered.start(0) >= this._config.autoCleanupMaxBackwardDuration) {
                         return true;
                     }

This issue body was partially generated by patch-package.

Nice! this is helpful!

wei10cool avatar Jul 28 '21 01:07 wei10cool

Thanks. Will apply.

xqq avatar Jul 28 '21 05:07 xqq

Failed to read the 'buffered' property from 'SourceBuffer': This SourceBuffer has been removed from the parent media source.

This exception shouldn't occur. What's your case or scene?

xqq avatar Jul 28 '21 13:07 xqq

就是正常播放,一开始加载出来了,然后就不停的报这个错,在我们的vue项目里面就是一直报错,然后还有一个react项目也有一个视频,也只一只报这个错,然后页面越来越卡,最后就不动了

------------------ 原始邮件 ------------------ 发件人: "bilibili/flv.js" @.>; 发送时间: 2021年7月29日(星期四) 上午8:58 @.>; @.>;"State @.>; 主题: Re: [bilibili/flv.js] Failed to read the 'buffered' property from 'SourceBuffer': This SourceBuffer has been removed from the parent media source. (#677)

Failed to read the 'buffered' property from 'SourceBuffer': This SourceBuffer has been removed from the parent media source.

This exception shouldn't occur. What's your case or scene? edit flv.js see picture

this package still has some problem:not support ios.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub, or unsubscribe.

supphia avatar Jul 29 '21 01:07 supphia

SourceBuffer 从 parent media source 移除之后必然就不能再播放了,加检测条件都没有用

xqq avatar Jul 29 '21 02:07 xqq

我是在nuxt(vue)使用dplayer搭配flv.js播放flv,播放时即出现该错误

wei10cool avatar Jul 29 '21 06:07 wei10cool

@wei10cool 能否给个完整的异常时调用栈?

xqq avatar Jul 29 '21 06:07 xqq

@wei10cool 能否给个完整的异常时调用栈?

dplay 使用方式 切换chanel时发生异常,如下

<template>
  <div>
    <h3>video</h3>
    <v-btn @click="chchanel('a1')" color="primary">chanel_A1</v-btn>
    <v-btn @click="chchanel('a2')" color="primary">chanel_A2</v-btn>
    <div id="dplayer"></div>
  </div>
</template>


<script>
export default {
  head() {
    return {
      title: "myvideo",
      script: [{ src: "../flv.js" }, { src: "../DPlayer.min.js" }]
    };
  },
  data() {
    return {
      player: undefined,
      url: "https://xxx.xxx.xxx.xxx:8443/live/170.flv",
      type:'hls'
    };
  },
  methods: {
    chchanel: function(data) {
      this.url = `https://xxx.xxx.xxx.xxx:8443/live/${data}.flv`;
      this.player.pause();
      this.player.switchVideo({
        url: this.url,
        type: 'flv'
      });
      this.player.play();
    }
  },
  mounted() {
    this.player = new DPlayer({
      container: document.getElementById("dplayer"),
      video: {
        name: "FLV",
        url: this.url,
        type: "customFlv",
        customType: {
          customFlv: function(video, player) {
            const flvPlayer = flvjs.createPlayer(
              {
                type: 'flv',
                url: video.src,
                isLive: true
              },
              {
                enableStashBuffer: false,
                //fixAudioTimestampGap: false,
                isLive: true
              }
            );
            flvPlayer.attachMediaElement(video);
            flvPlayer.load();
          }
        }
      }
    });
    this.player.play();
  }
};
</script>

<style scoped></style>

wei10cool avatar Jul 29 '21 10:07 wei10cool

请给 exception call stack

xqq avatar Jul 29 '21 10:07 xqq

image

wei10cool avatar Jul 29 '21 10:07 wei10cool

我也遇到了 移动端浏览器播放flv视频的时候出现这个报错

gentlecoder avatar Sep 08 '21 02:09 gentlecoder

这个问题还在跟进吗?@xqq

gongzhibin avatar Dec 27 '21 09:12 gongzhibin

不用的flv实例没有及时清掉,就开始创建新的实例,就会产生这个问题。

shady-xia avatar Jul 20 '22 06:07 shady-xia

@shady-xia 为什么我及时清理了也还是会有这个问题呢

siifan168 avatar Aug 25 '23 08:08 siifan168

React 里用的 flv.js => 1.6.2版本 也出现以上问题: image

huangjihua avatar Sep 18 '23 13:09 huangjihua