Created
March 25, 2015 23:50
-
-
Save mheijkoop/07d4df5355f58b10c688 to your computer and use it in GitHub Desktop.
stream pulseaudio monitor to airplay
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var airtunes = require('../lib/'), | |
spawn = require('child_process').spawn, | |
argv = require('optimist') | |
.usage('Usage: $0 --host [host] --port [num] --pacat [path] --source [source] --volume [num] --password [string]') | |
.default('port', 5000) | |
.default('volume', 50) | |
.default('pacat', '/usr/bin/pacat') | |
.default('source', 'nullsink.monitor') | |
.demand(['host']) | |
.argv; | |
console.log('adding device: ' + argv.host + ':' + argv.port); | |
var device = airtunes.add(argv.host, argv); | |
device.on('status', function(status) { | |
console.log('status: ' + status); | |
if(status !== 'ready') | |
return; | |
var pacat = spawn(argv.pacat, [ | |
'-r', | |
'-d', argv.source, | |
'--format=s16le', | |
'--rate=44100', | |
'--channels=2' | |
]); | |
// pipe data to AirTunes | |
pacat.stdout.pipe(airtunes); | |
// detect if ffmpeg was not spawned correctly | |
pacat.stderr.setEncoding('utf8'); | |
pacat.stderr.on('data', function(data) { | |
console.log('pacat: ' + data); | |
if(/^execvp\(\)/.test(data)) { | |
console.log('failed to start ' + argv.ffmpeg); | |
process.exit(1); | |
} | |
}); | |
}); | |
// monitor buffer events | |
airtunes.on('buffer', function(status) { | |
console.log('buffer ' + status); | |
// after the playback ends, give some time to AirTunes devices | |
if(status === 'end') { | |
console.log('playback ended, waiting for AirTunes devices'); | |
setTimeout(function() { | |
airtunes.stopAll(function() { | |
console.log('end'); | |
process.exit(); | |
}); | |
}, 2000); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment