【问题标题】:video streaming node js video controls not working on local server视频流节点js视频控件在本地服务器上不起作用
【发布时间】:2020-03-26 18:57:47
【问题描述】:

我想将视频添加到 node.js 服务器,但是当我将它加载到服务器时,控件无法运行,为什么? (请尽量减少代码...以便理解)


//html5 video loading

<video width="320" height="240" controls>


  <source src="cat.mp4" type="video/mp4">

</video>

//未加载


<video width="320" height="240" controls>


  <source src="http://localhost:8080" type="video/mp4">



</video>


//my node js code is 

var http = require ("http");
var fs = require ("fs");

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

{
console.log ('request was made:'+req.url);
res.writeHead(200,{'Content-Type':'text/html'});
var myReadStream = fs.createReadStream(__dirname+ '/index.html','utf8');
myReadStream.pipe(res);

});


server.listen(8080,'127.0.0.1');
console.log('YO BOSS');

【问题讨论】:

  • 我在考虑 video.js 是否可行?
  • Video.js的使用与否与这里的问题无关。

标签: javascript node.js server video-streaming html5-video


【解决方案1】:

对于流媒体,浏览器通常不会只请求整个媒体文件。它将使用ranged requests 来启用搜索。

您的响应忽略了浏览器的范围请求,甚至没有告诉浏览器文件有多大。如果浏览器不知道它有多大,并且知道你不支持范围请求,它就无法加载适当的元数据并且无法知道文件有多大。

您可以自己实现所有这些,也可以使用 Express.static 为您处理。

【讨论】:

    【解决方案2】:

    其实答案超级简单\(^.^)// 我只是添加添加http://localhost:8080/cat.mp4 答案是在将 (cat.mp4) 添加到有效地址后写得很糟糕的地址中!

    【讨论】:

      猜你喜欢
      • 2019-01-28
      • 1970-01-01
      • 2014-11-06
      • 1970-01-01
      • 1970-01-01
      • 2020-05-15
      • 1970-01-01
      • 2021-09-20
      • 2016-09-02
      相关资源
      最近更新 更多