gpt4 book ai didi

jquery - 缓存为空时获取音频文件的持续时间属性的问题

转载 作者:行者123 更新时间:2023-12-02 23:17:11 27 4
gpt4 key购买 nike

我在获取音频/ mpeg(mp3)的元数据时遇到问题。

例如,我使用JS来获取音频文件的持续时间,并且当缓存为空时,持续时间值将返回“Infinity”(NaN)。

我已经尝试使用事件/属性预加载和onloadedmetadata,并且总是在缓存为空时无法获得音频的持续时间和其他属性。

注意:问题仅在我清除缓存时(或当访问者第一次访问该页面时)。

    audioElement = new Audio('http://www.html5rocks.com/en/tutorials/audio/quick/test.mp3');
console.log(audioElement);
audioElement.addEventListener("loadedmetadata", function(_event) {
var duration = audioElement.duration;
console.log( duration );
});

最佳答案

也许是因为您的媒体正在流式传输?

参见https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement

duration Read only double
The length of the media in seconds, or zero if no media data is available. If the media data is available but the length is unknown, this value is NaN. If the media is streamed and has no predefined length, the value is Inf.

关于jquery - 缓存为空时获取音频文件的持续时间属性的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16058178/

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