gpt4 book ai didi

javascript - 设置 HTML5 音频位置

转载 作者:IT王子 更新时间:2023-10-29 02:54:00 24 4
gpt4 key购买 nike

如何跳转到 HTML5 Audio 元素中的特定时间偏移量?

他们说你可以简单地设置他们的 currentTime property (强调我的):

The currentTime attribute must, on getting, return the current playback position, expressed in seconds. On setting, if the media element has a current media controller, then it must throw an INVALID_STATE_ERR exception; otherwise, the user agent must seek to the new value (which might raise an exception).

唉,它似乎不起作用(我在 Chrome 中需要它)。

有类似的问题,虽然没有答案。

最佳答案

要跳转音频文件,您的服务器必须正确配置。

客户端发送byte range requests寻找和播放文件的某些区域,因此服务器必须充分响应:

In order to support seeking and playing back regions of the media that aren't yet downloaded, Gecko uses HTTP 1.1 byte-range requests to retrieve the media from the seek target position. In addition, if you don't serve X-Content-Duration headers, Gecko uses byte-range requests to seek to the end of the media (assuming you serve the Content-Length header) in order to determine the duration of the media.

然后,如果服务器正确响应字节范围请求,您可以通过currentTime设置音频的位置:

audio.currentTime = 30;

参见 MDN 的 Configuring servers for Ogg media (实际上,这同样适用于其他格式)。

另请参阅 Configuring web servers for HTML5 Ogg video and audio .

关于javascript - 设置 HTML5 音频位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9563887/

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