WebM ビデオ ファイルをクライアントにストリーミングしようとしています。
最初のチャンク (約 4466 バイトの長さ) は、(appendBuffer を使用して) 「機能」し<video>
ます。ビデオの解像度に合わせてサイズ変更されていることがわかります。
3回目を追加した後に発生するエラーは次のとおりです。
Uncaught InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable.
のプロパティに次のエラーがありますSourceBuffer
:buffered
[Exception: DOMException]
クライアントコードは次のとおりです。
var client = new BinaryClient('ws://127.0.0.1:3080/binary-endpoint');
var ms = new MediaSource();
var sourceBuffer;
var video = document.querySelector('video');
var needUpdate = true;
var paused = true;
var busy = false;
var initial = true;
ms.addEventListener('sourceopen', function(e) {
console.log('The MediaSource has been opened: ', e)
sourceBuffer = ms.addSourceBuffer('video/webm; codecs="vorbis,vp8"');
ms.duration = 1000;
sourceBuffer.addEventListener('updatestart', function(e) {
busy = true;
});
sourceBuffer.addEventListener('updateend', function(e) {
console.log(e);
busy = false;
});
sourceBuffer.addEventListener('update', function(e) {
console.log('Update succeeded', e)
});
console.log('The SourceBuffer has been created', sourceBuffer);
}, false);
client.on('stream', function(stream, meta){
stream.on('data', function(data) {
var DATA = new Uint8Array(data);
if (needUpdate && !busy) {
sourceBuffer.appendBuffer(DATA);
}
if (!initial && paused) {
video.play();
paused = false;
}
initial = false;
});
});
video.src = window.URL.createObjectURL(ms);