I am trying to create an app that allows the users to dynamically change the track they are listening to. I am using sails.js on top of node. The issue that I am having is that when the user try to seek to a time in the song before or after the current time the song will start over.
this is the latest code that i have 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);
});
}
Found a media streaming module for node: https://github.com/obastemur/mediaserver
run:
npm install mediaserver --save
adjusted code:
'index': function (request, response) {
var AUDIOFILE = 'path/to/audio.mp3'
ms.pipe(request,response,AUDIOFILE);
}
Simply awesome module by https://github.com/obastemur. Hope this helps anyone who was having a similar issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With