Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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