From 39a509ccaa2bebc898bae7538b56764a00970c8b Mon Sep 17 00:00:00 2001 From: Gerrit Linnemann Date: Mon, 2 Nov 2015 17:02:40 +0100 Subject: [PATCH] ready4testing --- kitchenradio/app/radio.js | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/kitchenradio/app/radio.js b/kitchenradio/app/radio.js index 7a93ec4..5166a54 100644 --- a/kitchenradio/app/radio.js +++ b/kitchenradio/app/radio.js @@ -8,6 +8,7 @@ // load the things we need var spawn = require('child_process').spawn; +var exec = require('child_process').exec; var fs = require("fs"); var http = require('http'); var wget = require('wget'); @@ -69,14 +70,21 @@ exports.play = function(idx) { Log.inspect('Radio: Download completed', output); if(Helper.isDefinedAndNotNull(Child)) { + // kill active instances try { Child.kill(); } catch(err) { Log.error('Radio: Error killing process'); } } + + var catProcess = exec('cat ' + m3u + ' | grep http://'); + catProcess.stdout.on('data', function(data) { + Log.inspect('Radio: Play', data); + }); + - try { + /*try { var parsers = require('playlist-parser'); var M3U = parsers.M3U; @@ -85,11 +93,13 @@ exports.play = function(idx) { if(Helper.isDefinedAndNotNull(playlist[0])) { stream2play = playlist[0].file; + } else { + } } catch(e) { Log.error(e); - } - + }*/ + var Child = spawn( 'mplayer', [ @@ -98,22 +108,25 @@ exports.play = function(idx) { stream2play ] ); - + // listen for any response from the child Child.stdout.on('data', function(chunk) { - Log.log('Radio: ' + chunk); + Log.log('Radio: stdout: ' + chunk); }); - + // listen for any errors Child.stderr.on('data', function (chunk) { - Log.error('Radio: ' + chunk); + Log.error('Radio: stderr: ' + chunk); }); - + /*Child.on('exit', function (code){ Log.log('Radio: Child process exited with exit code ' + code); });*/ - - }); + }); + + download.on('error', function(err) { + Log.error('Radio: Error downloading playlist. ' + err); + }); } else { Log.error('Radio: No channel defined!'); }