I'm making a basic music player in C++ on an embedded Linux platform (Intel Edison).
It works by sending commands to the shell to play the music using mpg123
.
Playing the music is working fine, but now I need to add media controls. I'm using the mpg123
command to play my MP3 files and if you pass it the -C
flag then it listens for commands such as p
for pause, q
for quit, etc
I'm using the code from this other SO answer for executing the commands How to execute a command and get output of command within C++ using POSIX?
Now the thing is, when I run the command to play the selected song from c++ (eg. mpg123 -C /media/sdcard/Music/<songname>
) it hangs the c++ program until the command returns, which doesn't return until the song is done playing. I can eliminate that issue by using pthead
to run the command in a parallel thread, but that still doesn't allow me to enter commands as I need to.
I thought of maybe somehow running the command in another tty
, and then somehow passing the commands to mpg123
by sending them to the other tty
, but I was unable to find a way to do this. (and I'm not sure it's possable)
I've been trying to do this for hours, so now I'm ready to ask here for some help :)
Do any of you have any ideas on how to run the command without freezing the thread (in a pthread or whatever), and still be able to send commands to mpg123
?