Answer the question
In order to leave comments, you need to log in
Video tag loads video twice?
The server has a stream that sends a video file and writes statistics about the file download:
res.writeHead(200, {
'Content-Type': 'video/mp4',
'Content-Length': stat.size
});
readStream.on('open', function () {
startTime = Date.now();
readStream.pipe(res);
});
readStream.on('close', function (err) {
writeStat(fileName, Date.now() - startTime, stat.size);
});
readStream.on('error', function (err) {
res.end(err);
});
<video controls="controls">
<source src="http://localhost:3000/api/file/test.mp4">
</video>
Answer the question
In order to leave comments, you need to log in
It is necessary to look that there above in the server. Whether there are 2 connections that the socket gives 2 times?
as far as I remember, you need to do stream.on('data') if you want to subtract this date or probably write your own stream.
readStream is your stream or fs ?
If it's just fs, it's enough to do fs.createReadStream('./path-to-file.mp4').pipe(res).
You don't have to wait for the event to start.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question