使用fetchapi加载视频

发布于 2025-02-12 08:30:08 字数 981 浏览 1 评论 0原文

我正在尝试下载完整的视频,在实际播放它们或将它们添加到DOM之前为它们制作Blob链接,在这里

 const init = {method: 'GET',mode: 'no-cors',cache: 'default'};
 const request = new Request(mp4Url);

fetch(request, init)
.then((response) =>  response.blob())
.then(data=>
  {
    let vid = URL.createObjectURL(data)
    let htmlString =`
    <video id="video-${id}" class="video_player" src="${vid}" autoplay muted loop>
    </video>`

    let videoElem = parser.parseFromString(htmlString, "text/html");
    videoRoot.appendChild(videoElem.firstChild.children[1].firstChild)
  }
  );

blob:http://127.0.0.1:5501/b62d9895-a432-487e-b1bc-4c670fe4b30c 
net::ERR_REQUEST_RANGE_NOT_SATISFIABLE

从Chrome中获得的代码中的一点点,而从Firefox那里

HTTP “Content-Type” of “application/x-unknown-content-type” is not supported. Load of media resource blob:http://127.0.0.1:5501/b62d9895-a432-487e-b1bc-4c670fe4b30c  failed.

获得的代码确实是可能的吗?

i'm trying to download complete videos, making blob links for them before actually playing them or adding them to DOM, here the bit of my code that does that

 const init = {method: 'GET',mode: 'no-cors',cache: 'default'};
 const request = new Request(mp4Url);

fetch(request, init)
.then((response) =>  response.blob())
.then(data=>
  {
    let vid = URL.createObjectURL(data)
    let htmlString =`
    <video id="video-${id}" class="video_player" src="${vid}" autoplay muted loop>
    </video>`

    let videoElem = parser.parseFromString(htmlString, "text/html");
    videoRoot.appendChild(videoElem.firstChild.children[1].firstChild)
  }
  );

i'm getting

blob:http://127.0.0.1:5501/b62d9895-a432-487e-b1bc-4c670fe4b30c 
net::ERR_REQUEST_RANGE_NOT_SATISFIABLE

from chrome and this from firefox

HTTP “Content-Type” of “application/x-unknown-content-type” is not supported. Load of media resource blob:http://127.0.0.1:5501/b62d9895-a432-487e-b1bc-4c670fe4b30c  failed.

is something like this really possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文