How not connecting third-party modules to make an example http-server with video on the page?
1 answer
Here is a minimal example:
We take two videos from the w3c page for the video tag: http://www.w3schools.com/html/html5_video.asp
The files themselves:
http://www.w3schools.com/html/mov_bbb.mp4
http://www.w3schools.com/html/mov_bbb.oggMake the minimum html page (video-test.html):
<!doctype html> <title>Test with video</title> <video controls> <source src="mov_bbb.mp4" type="video/mp4"> <source src="mov_bbb.ogg" type="video/ogg"> Your browser does not support HTML5 video. </video>We write server code ($ server-video.js):
var http = require('http'); var fs = require('fs'); http.createServer(function (request, response) { var file = decodeURIComponent(request.url.substr(1)); var headers = {}; console.log(file); switch(file) { case "": case "video-test.html": file = "video-test.html"; headers['Content-Type'] = 'text/html; charset=UTF-8'; break; case "mov_bbb.mp4": headers['Content-Type'] = 'video/mp4'; break; case "mov_bbb.ogg": headers['Content-Type'] = 'video/ogg'; break; default: response.writeHead(404, { 'Content-Type': 'text/plain' }); response.end('Not found!'); return; } fs.stat(file, function (error, data) { if (error) { console.log(error); response.writeHead(500, { 'Content-Type': 'text/plain' }); response.end('An error occured while loading file information :('); } else if (!data.isFile()) { response.writeHead(403, { 'Content-Type': 'text/plain' }); response.end('Not a file'); } else { headers['Content-length'] = data.size; response.writeHead(200, headers); fs.createReadStream(file).pipe(response); } }); }).listen(8081);Run
node $server-video.jsMake sure that the video plays, only the rewind does not work.
We try to remove the mp4 version from the markup and see the same result.
Why doesn't rewind work?
This is probably due to the fact that chrome in this case wants to see support for partial-answers, which we have not implemented.
|