Skip to content

Instantly share code, notes, and snippets.

@arvindr21
Last active August 29, 2015 14:07
Show Gist options
  • Save arvindr21/440c5b1171b21c94d1e1 to your computer and use it in GitHub Desktop.
Save arvindr21/440c5b1171b21c94d1e1 to your computer and use it in GitHub Desktop.
/**
** http://www.sitepoint.com/web-foundations/mime-types-complete-list **
MIME Types for video
Video Type Extension MIME Type
Flash .flv video/x-flv
MPEG-4 .mp4 video/mp4
iPhone Index .m3u8 application/x-mpegURL
iPhone Segment .ts video/MP2T
3GP Mobile .3gp video/3gpp
QuickTime .mov video/quicktime
A/V Interleave .avi video/x-msvideo
Windows Media .wmv video/x-ms-wmv
**/
var http = require('http'),
fileSystem = require('fs'),
path = require('path');
http.createServer(function(request, response) {
if (request.url.indexOf('audio') > 0) {
var filePath = 'path_to_audio.mp3';
var stat = fileSystem.statSync(filePath);
response.writeHead(200, {
'Content-Type': 'audio/mpeg',
'Content-Length': stat.size
});
var readStream = fileSystem.createReadStream(filePath);
// We replaced all the event handlers with a simple call to util.pump()
readStream.pipe(response);
} else {
var filePath = 'path_to_video.mp4';
var stat = fileSystem.statSync(filePath);
response.writeHead(200, {
'Content-Type': 'video/mp4',
'Content-Length': stat.size
});
var readStream = fileSystem.createReadStream(filePath);
// We replaced all the event handlers with a simple call to util.pump()
readStream.pipe(response);
}
})
.listen(3000);
// To play audio files : http://localhost:3000/audio
// To play video files : http://localhost:3000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment