你可能想要的是MPlayer的从模式的输入,这可以很容易地从另一个程序给它的命令。您可以在此模式下启动MPlayer,方法是在启动时输入-slave
命令行选项。
在这种模式下时,MPlayer忽略它的标准输入绑定和代替接受可在由换行分隔一次发送一个文本命令的不同词汇。有关支持的命令的完整列表,请运行mplayer -input cmdlist
。
由于您已将问题标记为Qt,因此我假定您使用的是C++。下面是C中的示例程序演示如何使用MPlayer的从属模式:
#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;
}