我尝试获取媒体元素的缓冲部分(具体来说,我试图从video元素获取它,但我希望它也能够使用audio ),但是当我使用带有某种偏移量的start()或end()函数(例如0)时,日志返回以下错误:
IndexSizeError:索引或大小为负值或大于允许的数量
我的密码怎么了?
var mediaelement = function(e) {
return e.buffered.start(0);
}
console.log(mediaelement(document.querySelector('video')));发布于 2018-05-31 08:58:56
很可能,调用函数时还没有任何缓冲。
在调用e.buffered.length或TimeRanges.end()之前,应该向TimeRanges.end()添加一个检查
function getbufferedstart(el) {
if(el.buffered.length) {
return el.buffered.start(0);
}
else {
return 'avoided a throw';
}
}
var a = new Audio('https://dl.dropboxusercontent.com/s/8c9m92u1euqnkaz/GershwinWhiteman-RhapsodyInBluePart1.mp3');
a.onloadedmetadata = onwehavebufferedsomething;
console.log(getbufferedstart(a)); // avoided
console.log('really ?');
a.buffered.start(0); // Error
function onwehavebufferedsomething(evt) {
console.log("now it's ok");
console.log(getbufferedstart(a)); // 0
}body>.as-console-wrapper{max-height:100vh}
https://stackoverflow.com/questions/50618827
复制相似问题