使用 Node.js 将视频文件流式传输到 HTML5 视频播放器,以便视频控件继续工作
htmlweb developmentfront end technology更新于 2025/8/18 17:16:17
使用 createReadStream 将请求的部分发送到客户端。函数调用 createReadStream() 将返回一个可读的流。
示例
以下是代码 −
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);
});
相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

