我正在使用播放按钮从我的 qt 应用程序播放 mplayer。我有两个按钮,称为暂停和停止。对于播放按钮,我使用了 system ("mplayer "+s.toAscii()+"&");
其中 s
是播放列表。
对于暂停按钮,我使用了 system("p");
但它不起作用。我可以使用 system("ps -A |grep mplayer > PID.txt");
将 mplayer 的进程 ID 存储到文本文件中。
是否有任何命令可以使用 PId 停止和暂停 mplayer?
最佳答案
您可能想要的是 MPlayer 的从属模式输入,这样可以轻松地从另一个程序向其发出命令。您可以在启动 MPlayer 时为其指定 -slave
命令行选项,以此模式启动 MPlayer。
在此模式下,MPlayer 会忽略其标准输入绑定(bind),而是接受不同的文本命令词汇表,这些命令可以一次发送一个,并以换行符分隔。如需支持的命令的完整列表,请运行 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;
}
关于qt4 - 是否有使用 PId 停止和暂停 mplayer 的命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5163983/