我想知道如何使用从fs.createReadStream
获得的数组缓冲区或块播放媒体吗?
示例:
const chunks = [];
const readStream = fs.createReadStream('6381.mp4');
readStream.on('data', chunk => {
chunks.push(toArrayBuffer(chunk));
});
readStream.on('end', () => {
// here I'm sending the chunks to the client
});
function toArrayBuffer(buf) {
var ab = new ArrayBuffer(buf.length);
var view = new Uint8Array(ab);
for (var i = 0; i < buf.length; ++i) {
view[i] = buf[i];
}
return ab;
}
客户:
const data = new Blob(ArrayBufferTest);
var url = URL.createObjectURL(data);
this.video.current.src = url;
this.video.current.load();
this.video.current.onloadeddata = () => {
this.video.current.play();
console.log('hi');
};
但是它不起作用, 如何处理浏览器中的块来播放? 有人可以帮我吗?