在下面的代码中,console.log(sb.buffered)给了我一个长度为0的TimeRanges对象。为什么会这样?我检查了xhr.response是什么,它是一个大约58000字节长度的ArrayBuffer。
var ms;
var sb;
var mimeCodec = 'video/mp4; codecs="avc1.42E01E, mp4a.40.2"';
function example() {
ms = new MediaSource;
var video = document.querySelector('video');
video.src = URL.createObjectURL(ms);
ms.addEventListener('sourceopen', function() {
sb = ms.addSourceBuffer(mimeCodec);
fetch('test0.mp4');
}, false);
}
function fetch(url) {
var xhr = new XMLHttpRequest;
xhr.open('get', url);
xhr.responseType = 'arraybuffer';
xhr.onload = function() {
if (ms.readyState === 'open') {
sb.appendBuffer(xhr.response);
sb.addEventListener('updateend', function() {
console.log(sb.buffered);
});
}
};
xhr.send();
}