【发布时间】:2020-03-12 21:59:49
【问题描述】:
我使用plyr.js 创建一个视频播放器。
遇到hls.js 的错误:
Uncaught DOMException: Failed to read the 'buffered' property from 'SourceBuffer':
This SourceBuffer has been removed from the parent media source.
当我在路线更改时更改视频src 时会发生这种情况。
我的播放器:
import React from 'react'
import HLS from 'hls.js'
import Plyr from 'plyr'
const Player = ({src}) => {
const [player, setPlayer] = useState(null);
const video = useRef(null);
useEffect(() => {
const node = video.current;
// Thought it would help, but no
const destroy = () => {
if (window.hls) {
window.hls.stopLoad();
window.hls.detachMedia();
window.hls.destroy();
}
};
if (node) {
if(!player) setPlayer(new Plyr(node, {captions: {active: true, update: true}}))
if (HLS.isSupported()) {
destroy();
window.hls = new HLS();
window.hls.loadSource(src);
window.hls.attachMedia(node);
} else node.src = src;
}
}, [src, player]);
return (
<div>
<video ref={video} src={src} controls/>
</div>
)
};
【问题讨论】:
-
视频类型是什么?您尝试了其他视频源吗?
-
@AhedKabalan, mp4
-
您是否尝试过其他视频源?我认为是视频格式的问题。
-
@AhedKabalan,嗯,让我检查一下
标签: javascript reactjs http-live-streaming hls.js plyr.js