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;
}