2015-12-06 170 views
0

我在寫一個家庭自動化web應用程序。我有從Google音樂流到我的揚聲器的音樂,我使用vlc輸出聲音。我無法做的事似乎是暫停歌曲。例如,cvlc url會打開並流式傳輸url,然後進入交互模式,在這種模式下可以鍵入暫停並暫停。打開終端,執行命令並進入交互模式

當我嘗試從我的node.js應用程序執行此操作時,沒有任何反應。它只是繼續玩。

var terminal = require('child_process').spawn('bash'); 

terminal.stdout.on('data', function (data) { 
    console.log(data); 
}); 

terminal.on('exit', function (code) { 
    console.log('child process exited with code ' + code); 
}); 

terminal.stdin.write('cvlc "' + req.url +'" & \n'); 
terminal.stdin.write('pause'); 

回答

0

嘗試把一個「\ n」暫停命令後:

terminal.stdin.write('pause\n'); 

另外,我不熟悉CVLC,但是,如果你在BG啓動它,不知道,你可以寫入其標準輸入,因此它可能會忽略所有'暫停'命令中的所有內容,您是否嘗試在沒有'&'的情況下調用它?

另外,爲什麼開始一個bash,然後運行cvlc?爲什麼不:

var terminal = require('child_process').spawn('cvlc'); 

最後但並非最不重要,你確定默認路徑是否足夠?

+0

更改爲,var terminal = require('child_process'); term = terminal.spawn('cvlc',[req.url]); term.stdin.write( '暫停\ n');仍然開始播放歌曲,然後不會暫停。 –

+0

而且默認路徑應該沒問題。如果我在直線終端中運行相同的命令,它會提示您可以鍵入暫停,播放,快速等等......基本上我希望能夠調出提示並與之交互。 –

+0

你有沒有從stdout中獲得任何東西?順便說一句,標準輸出是一個十六進制緩衝區,你最好做:console.log(data.toString()); – Meir

0

我從來沒有真正通過終端計算出來。相反,我使用VLC的http服務器選項,然後確實獲得控制暫停和播放的請求。

菌種:

var term = spawn.spawn('cvlc',['-I', 'http',req.url,'localhost:8080']); 

暫停:

var req = http.get('http://:[email protected]:8080/requests/status.xml?command=pl_pause', function (r) { 
    r.on('data', function() { /* do nothing */ 
    }); 
}); 

和播放:

var reqd = http.get('http://:[email protected]:8080/requests/status.xml?command=pl_play', function (r) { 
     r.on('data', function() { /* do nothing */ 
     }); 
     r.on('error', function (err) { /* do nothing */ 
      console.log(err) 
     }); 
    }); 

希望幫助別人用VLC控制問題。我是通過無頭的樹莓派來做到這一點的。我試圖避免爲我的揚聲器購買Chromecast並獲得成功。

相關問題