我正在fetch()从 API 获取视频。
这response.body是一个可读的流。所以我把它读进了reader.
然后将所有块 ( value) 推入块数组 ( chunks.push(value)) 中。
然后,块数组被转换为 arrayBuffer ( let buffer = await blob.arrayBuffer()),因为 blob 无法附加到 sourceBuffer。
以上所有步骤均正确运行!我唯一的问题是将缓冲区附加到 sourceBuffer ( sourceBuffer.appendBuffer(buffer)) 中。
控制台没有弹出错误,但 sourceBuffer 没有更新。它保持空着。
有人知道发生了什么事吗?
多谢
<body>
<video id="test-video-api">
</video>
<script>
const fetchUrl = "https://myserver/api/video?fuid=12345";
const videoTag = document.getElementById("test-video-api");
function getVideo(){
if (window.MediaSource) {
var mediaSource = new MediaSource();
videoTag.src = URL.createObjectURL(mediaSource);
mediaSource.addEventListener('sourceopen', sourceOpen);
} else {
console.log("The Media Source Extensions API is not …Run Code Online (Sandbox Code Playgroud)