如何在浏览器中播放mp3文件中的缓冲区数组?

时间:2019-06-03 15:16:52

标签: javascript html node.js streaming media

我想知道如何使用从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');
    };

但是它不起作用, 如何处理浏览器中的块来播放? 有人可以帮我吗?

0 个答案:

没有答案