我从nodejs构建流服务。这是我的服务器代码server.js
var http = require('http'),
fs = require('fs'),
util = require('util');
http.createServer(function (req, res) {
var path = __dirname+'/movie.mp4';
var stat = fs.statSync(path);
var total = stat.size;
if (req.headers['range']) {
var range = req.headers.range;
var parts = range.replace(/bytes=/, "").split("-");
var partialstart = parts[0];
var partialend = parts[1];
var start = parseInt(partialstart, 10);
var end = partialend ? parseInt(partialend, 10) : total-1;
var chunksize = (end-start)+1;
console.log('RANGE: ' + start + ' - ' + end + ' = ' + chunksize);
var file = fs.createReadStream(path, {start: start, end: end});
res.writeHead(206, { 'Content-Range': 'bytes ' + start + '-' + end + '/' + total, 'Accept-Ranges': 'bytes', 'Content-Length': chunksize, 'Content-Type': 'video/mp4' });
file.pipe(res);
} else {
console.log('ALL: ' + total);
res.writeHead(200, { 'Content-Length': total, 'Content-Type': 'video/mp4' });
fs.createReadStream(path).pipe(res);
}
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');
这是我的Page.html
<!DOCTYPE html>
<html>
<body>
<video scr="http://localhost:1337" preload autoplay controls></video>
</body>
</html>
视频代码不会显示任何视频,但当我在浏览器的地址中输入地址http://localhost:1337时,它会播放视频。
如何在我的页面中将视频转换为视频标签?可能是我应该使用一些js代码客户端?
答案 0 :(得分:0)
解决。我的视频代码中的语法错误&#34; src&#34;不是&#34; scr&#34;