Python スクリプトを使用して、rpi3 のコマンド ラインで omxplayer を制御しようとしています。subprocess.Popen を呼び出して制御します (再生/一時停止、音量の増減など)。標準入力 (例: p、+/- など)、文字は send_signal で変数テキストとして渡され、通信を使用して制御できません。より良い方法はありますか?
編集: また、player.stdin.write(text); player.stdin.flush() は機能しません。
def start_music():
player = subprocess.Popen(['omxplayer', songs[0]], stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.STDOUT)
return player
def send_signal(player, text):
player.communicate(text.encode('utf-8'))
player.stdin.close()
omxplayer の代わりに cat -e を試してみると、出力は次のようになります。
why_dont_you work
test_input
test_input$
test_input2
test_input2$
a
a$
どういうわけか最初の行が再び表示されないことに注意してください