Note that there are some explanatory texts on larger screens.

plurals
  1. PONodejs mp3 streaming
    primarykey
    data
    text
    <p>I am try to create a small nodejs server that will take requests that will stream audio. I'm currently using 0.10.5 api. I must admit I am a newbie to nodejs. I'm not sure how to edit this code to successfully stream audio.</p> <pre><code> var http = environment.http; //Steaming Audio var path = environment.path, util = environment.util, url = environment.url; http.createServer(function (request, response) { var queryData = url.parse(request.url, true).query; window.console.log(queryData); if (!queryData.hasOwnProperty('file')) { response.writeHead(404, { 'Content-Type': 'text/plain' }); response.end(); window.console.log('In here'); } else { window.console.log('In here2'); var filePath = queryData.file; var extension = self.getExtension(filePath); var acceptedExtensions = ['mp3', 'wav', 'aiff']; if ($.inArray(extension, acceptedExtensions) == -1) { response.writeHead(404, { 'Content-Type': 'text/plain' }); response.end(); } var stat = environment.fs.statSync(filePath); response.writeHead(200, { 'Content-Type': 'audio/mpeg', 'Content-Length': stat.size }); //window.console.log(filePath); var readStream = environment.fs.createReadStream(filePath); //var readable = new require('stream').Readable(); readStream.pipe(response); } }).listen(10000); </code></pre> <p>When I make a request <code>http://localhost:10000/?file=/Users/acasanova/Music/Cass%20Beats/45th.mp3</code> The console shows "In here2" and then "In here". I'm trying to figure out why it seems to fulfill the request twice and why the audio isn't being streamed.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload