I created a simple server that uses the fs module to stream an mp3 file to a browser that plays it in the html5 sound element. Be that as it may, the audio streams work fine, however I cannot search through the stream, even if the part that I am referring to is already buffered.
var express = require('express');
var app = express();
var fs = require('fs');
app.get('/', function (req, res) {
var filePath = 'music.mp3';
var stat = fs.statSync(filePath);
res.writeHead(200, {
'Content-Type': 'audio/mpeg',
'Content-Length': stat.size,
});
var readStream = fs.createReadStream(filePath);
readStream.pipe(res);
});
Other similar questions & As suggested to add the Content-Range header, but I can not find a simple example of how to do this. Others say they use the 206 Partial-Content header, but when I do this, the sound will not play at all.
Here is a demo (testing on Chrome on Windows)
source
share