美文网首页
nodejs视频流输出

nodejs视频流输出

作者: 多啦梦_1adc | 来源:发表于2020-06-10 11:30 被阅读0次

废话不多说,直接上效果和代码

代码

var fs = require('fs');

var url = require("url");

var server = require('http').createServer(function(req, res) {

if(req.url != "/favicon.ico"){

     var pathname = url.parse(req.url).pathname;

     if(pathname == "/"){

          res.writeHead(200, {'Content-Type': 'video/mp4'}); 

          var rs = fs.createReadStream('./abc.mp4'); 

          rs.pipe(res); 

          rs.on('end',function(){ 

            res.end(); 

            console.log('end call'); 

          }); 

     }else if(pathname == "/sp"){

             var datas = fs.readFileSync("./1.html","utf-8")

             res.writeHead(200, {'Content-Type': 'text/html'}); 

             res.write(datas);

             res.end(" ");

     }

 }

}).listen(3000)

server.on("error",function(res){

console.log("err:",res)

})

<html>

<head> </head> <body> <video width="320" height="240" controls="controls"> <source src="/" type="video/mp4"> nook </video> </body>

</html>

相关文章

网友评论

      本文标题:nodejs视频流输出

      本文链接:https://www.haomeiwen.com/subject/qzvutktx.html