Node.js sends an audio file and lets the user search
I am trying to create an application that allows users to dynamically change the track they are listening to. I am using sails.js on top of node. The problem I'm running into is that when the user tries to find a time in a song before or after the current time, the song will start playing.
this is the last code i tried to implement on the server.
'index': function (request, response) {
var path = require('path');
var fs = require('fs');
var filePath = path.join('path\to\folder','music.mp3')
var stat = fs.statSync(filePath);
response.writeHead(200, {
'Content-Type': 'audio/mpeg',
'Content-Length': stat.size
});
fs.readFile(filePath,function (err,data) {
response.send(data);
});
}
+3
source to share
1 answer
Found a multimedia streaming module for node: https://github.com/obastemur/mediaserver
mileage:
npm install mediaserver --save
corrected code:
'index': function (request, response) {
var AUDIOFILE = 'path/to/audio.mp3'
ms.pipe(request,response,AUDIOFILE);
}
Just awesome module https://github.com/obastemur . Hope this helps anyone who has had a similar problem.
+2
source to share