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

切换视频调用了flv.destroy,仍然会继续拉流

Open quickfight opened this issue 4 years ago • 3 comments

flv.js 1.5.0+react16.12.0 我做的是直播流应用,有一个对话框,左侧有摄像头的菜单,选择摄像头后右侧播放视频。 我能确保每次切换摄像头视频flvjs的destroy方法被调用了,但是多切换几次会发现,本已被销毁的上次播放地址还在有流量产生,最后即使完全关闭对话框后fetch-stream-loader.js:118仍然继续有流量产生,只要不刷新页面就不会停。 我尝试打印日志,发现118行的_requestAbort已经是true了,可以证明,该js的stop方法是被destroy调用过的。 这时在html的dom里也确保没有video 标签存在。 请问有办法解决吗?还是说在flvjs加载后要有个延迟才能调用destroy或者什么注意点,多谢。

quickfight avatar Mar 13 '20 08:03 quickfight

找到解决方案了,抱歉 https://github.com/bilibili/flv.js/pull/448/files#diff-2236408d6aad747aed1a901e3aac73feR120-R125

quickfight avatar Mar 13 '20 12:03 quickfight

very nice

SilurianYang avatar Apr 23 '20 06:04 SilurianYang

// 源码fetch-stream-loader.js@174
abort() {
    this._requestAbort = true;

    if (this._status !== LoaderStatus.kBuffering || !Browser.chrome) {
        // Chrome may throw Exception-like things here, avoid using if is buffering
        if (this._abortController) {
            try {
                this._abortController.abort();
            } catch (e) {}
        }
    }
}

这里有判断,在谷歌浏览器中还是会执行继续加载

wtto00 avatar Aug 30 '22 02:08 wtto00