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

PHPz
Release: 2023-09-08 10:53:02
forward
1400 people have browsed it

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);
});
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!