我目前正在尝试通过socket.io将.webm视频文件传输到我的客户端(目前使用Chrome作为客户端)。
将第一个Uint8Array
附加到SourceBuffer工作正常,但追加更多的不起作用并抛出以下错误:
Uncaught DOMException: Failed to execute 'appendBuffer' on 'SourceBuffer': The HTMLMediaElement.error attribute is not null.
我目前的代码:
'use strict';
let socket = io.connect('http://localhost:1337');
let mediaSource = new MediaSource();
let video = document.getElementById("player");
let queue = [];
let sourceBuffer;
video.src = window.URL.createObjectURL(mediaSource);
mediaSource.addEventListener('sourceopen', function() {
sourceBuffer = mediaSource.addSourceBuffer('video/webm; codecs="vorbis,vp8"');
socket.on("video", function(data) {
let uIntArray = new Uint8Array(data);
if (!sourceBuffer.updating) {
sourceBuffer.appendBuffer(uIntArray);
} else {
queue.push(data);
}
});
});
服务器端代码(代码段)
io.on('connection', function(socket) {
console.log("Client connected");
let readStream = fs.createReadStream("bunny.webm");
readStream.addListener('data', function(data) {
socket.emit('video', data);
});
});
我还删除了webkit检查,因为这只会在Chromium浏览器上运行。
答案 0 :(得分:2)
我认为你必须释放缓冲区,请参阅remove()函数 http://w3c.github.io/media-source/#widl-SourceBuffer-remove-void-double-start-unrestricted-double-end
如果有帮助,请告诉我。