Google Chrome未缓冲我正在通过快递服务器流式传输的音频

时间:2018-11-10 11:56:07

标签: html5 google-chrome html5-audio audio-streaming

我正在通过Express服务器将从Gridfs存储桶中检索到的音频分流传输到客户端的html音频元素,直到它们可用。 Edge和Firefox都下载并缓冲歌曲,并允许我查找缓冲的歌曲,而chrome似乎不缓冲它,而是顺序下载块(我可能错了)。

服务器端:

trackRoute.get('/:trackID', (req, res) => {
    try{
        var trackID = new ObjectID(req.params.trackID);
    }
    catch(err){
        return res.status(400).json({ message:" :Invalid trackID in URL parameter. Must be a single String of 12 bytes or a string of 24 hex characters" });
    }

    res.set('content-type', 'audio/mp3');
    res.set('accept-ranges', 'bytes');
    res.set('Transfer-Encoding', 'chunked');

    let bucket = new mongodb.GridFSBucket(db,
        {
            bucketName: 'songs'
        }
    );

    let downloadStream = bucket.openDownloadStream(trackID);

    // downloadStream.pipe(res);

    downloadStream.on('data', (chunk) => {
        res.write(chunk);
    });

    downloadStream.on('error', (err) => {
        res.sendStatus(404);
    });

    downloadStream.on('end', () => {
        res.end();
    });

    // let readableSongStream = fs.createReadStream("C:\\Users\\Sajeel\\Music\\Demons - Imagine Dragons.mp3");
    // readableSongStream.pipe(res);
});

网络快照


Chrome:

Taking 2.3 mins and still wont let me seek the song until whole song is already played

Firefox:

131ms

边缘:

1.09s

0 个答案:

没有答案