Home  >  Article  >  Web Front-end  >  Stream video files to HTML5 video player using Node.js so video controls continue to work

Stream video files to HTML5 video player using Node.js so video controls continue to work

PHPz
PHPzforward
2023-09-08 10:53:021414browse

Stream video files to HTML5 video player using Node.js so video controls continue to work

Use createReadStream to send the requested portion to the client. The function call createReadStream() will give you a readable stream.

Example

The following is the code -

stream = fs.createReadStream(path);
stream.on('open', function () {
   res.writeHead(206,{
      "Content-Range":"bytes " + begin + "-" + end + "/" +total, "Accept-Ranges":"bytes",
         "Content-Length":chunksize, "Content-Type":"new/mp4"
   });
   stream.pipe(res);
});

The above is the detailed content of Stream video files to HTML5 video player using Node.js so video controls continue to work. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete