C
C
Coder3212017-05-12 21:29:59
HTML
Coder321, 2017-05-12 21:29:59

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);
            });

The first question is, is it correct to consider this as the start of the open event of the stream and the end of the close event?
And the second question. At the front I receive video:
<video controls="controls">
  <source src="http://localhost:3000/api/file/test.mp4">
</video>

but why is the video loaded twice
d6b8998180374777a06d16d2fafd30a5.jpg
why is this happening?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg Lustenko, 2017-05-24
@fakey0u

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 question

Ask a Question

731 491 924 answers to any question