Skip to content

Instantly share code, notes, and snippets.

@tanepiper
Created April 6, 2011 12:19
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save tanepiper/f9f1b5b39c74c7dd12b9 to your computer and use it in GitHub Desktop.
Save tanepiper/f9f1b5b39c74c7dd12b9 to your computer and use it in GitHub Desktop.
An express app for streaming mp3 files
fs = require 'fs'
path = require 'path'
util = require 'util'
express = require 'express'
app = module.exports = express.createServer()
app.get '/', (req, res, next) ->
music_path = path.join __dirname, 'music'
fs.readdir music_path, (error, files) ->
output = []
for file in files
output.push "<audio controls preload=\"auto\" autobuffer src=\"http://192.168.253.142:9001/play/#{file}\"></audio>"
output.push '<br />'
res.send output.join('\n'), {"content-type": "text/html"}, 200
app.get '/play/:file', (req, res, next) ->
filePath = path.join __dirname, 'music', req.param 'file'
stat = fs.statSync filePath
res.header 'content-type', 'audio/ogg'
res.header 'content-length', stat.size
res.sendfile filePath
app.listen 9001
@gabhi
Copy link

gabhi commented Aug 28, 2014

where is streaming in this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment