I am playing mplayer from my qt application using the play button. I have two buttons called pause and stop. For play button I used system ("mplayer "+s.toAscii()+"&");
where s
is the playlist.
For the pause button I used system("p");
but it is not working. I am able to store the process id of mplayer to a text file using system("ps -A |grep mplayer > PID.txt");
.
Is there any command to stop and pause the mplayer using the PId?
What you probably want is MPlayer's slave mode of input, which makes it easy to give it commands from another program. You can launch MPlayer in this mode by giving it the -slave
command line option when launching it.
In this mode, MPlayer ignores its standard input bindings and instead accepts a different vocabulary of text commands that can be sent one at a time separated by newlines. For a full list of commands supported, run mplayer -input cmdlist
.
Since you have tagged the question as Qt, I'm going to assume you are using C++. Here's an example program in C demonstrating how to use MPlayer's slave mode:
#include <stdio.h>
#include <unistd.h>
int main()
{
FILE* pipe;
int i;
/* Open mplayer as a child process, granting us write access to its input */
pipe = popen("mplayer -slave 'your_audio_file_here.mp3'", "w");
/* Play around a little */
for (i = 0; i < 6; i++)
{
sleep(1);
fputs("pause\n", pipe);
fflush(pipe);
}
/* Let mplayer finish, then close the pipe */
pclose(pipe);
return 0;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With