gpt4 book ai didi

javascript - Android - 当互联网中断时继续使用 HTML5 javascript 播放音频 - 获取、blob

转载 作者:行者123 更新时间:2023-12-03 01:35:40 24 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





Pre-loaded sounds being unloaded?

(2 个回答)


3年前关闭。




我想预加载一个完整的 mp3 文件,以便当互联网中断时该页面可以在计算机和移动设备上继续工作。我找到并尝试了以下代码,它似乎可以在我的 Windows 7 桌面上运行,但不适用于我的 Android。 Android 不会在 fetch 语句上失败,但似乎在“.then(r => r.blob())”语句上失败。应该先声明 r 吗?为什么android失败的任何想法。我无法访问 Android 控制台。

fetch("https://foo.com/foo2/foo4.mp3")
.then(r => r.blob()) // could be xhr.responseType = 'blob'
.then(blob => {
aud = new Audio(URL.createObjectURL(blob));
document.body.appendChild(aud);
console.log('Fully loaded and cached until the page dies...')
});

最佳答案

有一个 preload 属性你可以试试`

预载

This enumerated attribute is intended to provide a hint to the browser about what the author thinks will lead to the best user experience. It may have one of the following values:

  • none: Indicates that the audio should not be preloaded.
  • metadata: Indicates that only audio metadata (e.g. length) is fetched.
  • auto: Indicates that the whole audio file can be downloaded, even if the user is not expected to use it. empty string: A synonym of the auto value.

If not set, preload's default value is browser-defined (i.e. each browser may have its own default value). The spec advises it to be set to metadata.

关于javascript - Android - 当互联网中断时继续使用 HTML5 javascript 播放音频 - 获取、blob,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53385662/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com