I'm trying to make mobile app that can play audio files, but, that audio files are big, more than 100 mb, and I don't want save this file into the device, I want make a stream to this file into the browser.
I'm building a prototype only with ionicframework and phonegap plugins this is my github of the project: https://github.com/cmarrero01/famvoice My server is in node.js, so my first intent was make the streaming of the audio file with node.js to the audio tag, something like this:
app.get('/record/:userId/:playListId/:recordName',function(req,res){
var userId = req.params.userId;
var playListId = req.params.playListId;
var recordName = req.params.recordName;
if(!userId || !playListId || !recordName){
res.end();
return;
}
var path = "./records/"+recordName;
if (!params.fs.existsSync(path)) {
res.end();
return;
}
res.setHeader("content-type", "audio/mpeg");
var stream = params.fs.createReadStream(path, { bufferSize: 64 * 1024 });
stream.pipe(res);
}
And in the ionic html the audio tag:
<audio controls preload="none" type="audio/mpeg" autoplay>
<source ng-src="{{audioPlay | trustAsResourceUrl}}" />
</audio>
This is was a bad, bad, bad Idea, when I add the src to the audio tag, this wait to download all file to start playing it, so this is really an streaming, this is the same that I download the file an run it.
So, my second thought was ffmpeg, ffserver. I install ffmpeg, and I run ffserver with this config file:
Port 8090
BindAddress 0.0.0.0
MaxHTTPConnections 2000
MaxClients 1000
MaxBandwidth 1000
CustomLog -
<Feed feed1.ffm>
File /tmp/feed1.ffm
FileMaxSize 200K
ACL allow 127.0.0.1
</Feed>
<Stream status.html>
Format status
ACL allow 127.0.0.1
ACL allow localhost
ACL allow 192.168.0.0 192.168.255.255
</Stream>
<Stream test.mp3>
Feed feed1.ffm
Format mp2
AudioCodec libmp3lame
AudioBitRate 128
AudioChannels 1
AudioSampleRate 44100
NoVideo
</Stream>
And then run the next command:
ffmpeg test.mp3 http://IP:PORT/feed1.ffm
This command send to the feed the audio file test.mp3, and if you access to the url: http://IP:PORT/test.mp3 you can listen.. BUT, HERES IS MY BIG PROBLEM...
My Problems are:
The ffmpeg send the file to the feed, when the the process finished if you can try to access to the that url, you can't listen anything and the URL is stay loading.
Is suppouse that the user can select a file to listen, how I make to stream a specific file to a spefic user and not change stream for all users. I suppouse that I need one feed per user?
Exist some way to send the stream to node.js and node.js send it to the app with the correct codecs and stuff?.
If the ffmpeg is not the best way, what it is?
Thanks.