我正在使用
HTML5和jQuery构建mp3播放列表播放器.在这个播放器中,有一个水平条逐渐与mp3文件的缓冲存在一起增长.
这是我的完整代码:
get buffered end
HTML5:
<audio id="music" controls> <source src="https://archive.org/download/musicTestAudio27/Very%20nice%20%2827%29.mp3" type="audio/mpeg"> </audio> <br/> <div id="buffered"></div>
CSS:
#buffered{ border:solid #ccc 1px; height:10px; background:red; display:block; width:1%; }
使用Javascript:
var track = document.getElementById("music"); setInterval(function(){ var w = 100*(track.buffered.end(0))/track.duration; $('#buffered').css("width",w+"%"); },1000);
但Firefox给我一条错误消息说:
IndexSizeError: Index or size is negative or greater than the allowed
amountvar w = 100*(track.buffered.end(0))/track.duration;
和谷歌铬合金说:
Uncaught IndexSizeError: Failed to execute ‘end’ on ‘TimeRanges’: The
index provided (0) is greater than or equal to the maximum bound (0).