Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It is not possible to achieve this in JavaScript. However, you might be able to run it from the browser with an <a href="https://developer.mozilla.org/En/Plugins" rel="nofollow">NPAPI</a> plugin (with great pain).</p> <p>If you can run a local server, there are several node.js modules which make this much easier. The following example will stream any audio file that is posted to a nearby AirPlay device.</p> <ul> <li>It requires the <a href="https://github.com/lperrin/node_airtunes/" rel="nofollow">airtunes</a> module from NPM, which I maintain.</li> <li>It uses <a href="http://ffmpeg.org/" rel="nofollow">FFmpeg</a> to transcode the file.</li> </ul> <p>You can test it with:</p> <pre><code>curl -X POST --data-binary @sample.mp3 http://localhost:8080/audio </code></pre> <p>It assumes that FFmpeg is located in /usr/local/bin/ffmpeg, and that an AirPlay device is available on localhost:5000 (you can try with Airfoil Speakers).</p> <pre><code>var airtunes = require('airtunes'), express = require('express'), app = express(), device = airtunes.add('localhost'), spawn = require('child_process').spawn; app.post('/audio', function(req, res) { // use ffmpeg to reencode data on the fly var ffmpeg = spawn('/usr/local/bin/ffmpeg', [ '-i', 'pipe:0', // Read from stdin '-f', 's16le', // PCM 16bits, little-endian '-ar', '44100', // Sampling rate '-ac', 2, // Stereo 'pipe:1' // Output to stdout ]); // pipe data to AirTunes ffmpeg.stdout.pipe(airtunes, { end: false }); // detect if ffmpeg was not spawned correctly ffmpeg.stderr.setEncoding('utf8'); ffmpeg.stderr.on('data', function(data) { if(/^execvp\(\)/.test(data)) { console.log('failed to start ' + argv.ffmpeg); process.exit(1); } }); req.pipe(ffmpeg.stdin); req.on('end', function() { res.end(); }); }); device.on('status', function(status) { console.log('status: ' + status); }); console.log('listening on port 8080'); app.listen(8080); </code></pre> <p></p>
 

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