Running mpg123 with FIFO control?

2019-08-08 04:30发布

I need to run mpg123 with a single file, such that it will autostart and autoclose, like it normally does, however, I need to be able to override this default behavior with commands sent to a fifo file.

I had been running mpg123 filename.mp3 from a script, and simply waiting for it to finish before moving on. However, I'd like another script to be able to pause playback, control volume, or kill the process early, depending on the user's input.

mpg123 -R --fifo /srv/http/newsctl filename.mp3 seems to start mpg123 and create the pipe, but does not start playback.

How do I make this work?

标签: bash media fifo
1条回答
迷人小祖宗
2楼-- · 2019-08-08 05:08

Unfortunately mpg123 is unable to play a specified file when -R argument is used. To start the playback you have to load a file using created fifo.

FIFO_MPG='/srv/http/newsctl'
mpg123 -R --fifo "$FIFO_MPG"
echo 'load filename.mp3' >> "$FIFO_MPG"

Also I suggest you to silence verbose output by using

echo 'silence' >> "$FIFO_MPG"

I hope it is not too late. Good luck! ;)

查看更多
登录 后发表回答