2011-03-02 34 views
5

我正在使用播放按钮从我的qt应用程序中播放mplayer。我有两个按钮叫做暂停和停止。对于我使用的播放按钮system ("mplayer "+s.toAscii()+"&");,其中s是播放列表。是否有使用PId停止和暂停mplayer的命令?

对于我使用的暂停按钮system("p");,但它不起作用。我可以使用system("ps -A |grep mplayer > PID.txt");将mplayer的进程ID存储到文本文件中。

是否有任何命令停止和暂停使用PId的mplayer?

回答

0

据我所知,没有PID。不过检查一下slave模式(-slave)。来自man mplayer:

开启从属模式,其中MPlayer作为其他程序的后端。 MPlayer不会拦截键盘事件,而会从标准输入读取由换行符(\ n)分隔的命令。

你可以完全控制它。

6

你可能想要的是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; 
} 
0

是在从模式下使用MPlayer的。这样你就可以从程序中传递命令给它。看看qmpwidget。它的开源并且应该解决你所有的麻烦。对于命令,请检查mplayer网站或搜索mplayer从属模式命令。

0

我在使用mplayer的QT中编写了一个类似的程序。我使用QProcess来控制mplayer。

以下是部分代码。在函数playstop()中,您只需发送“q”并存在mplayer。如果你发送“p”,它会暂停mplayer.I希望它对你有用。

Main.h

#ifndef MAIN_H 
#define MAIN_H 
#include "process.h" 
class Main : public QMainWindow 
{ 
public: 
    Process m_pProcess1; 
Q_OBJECT 
public: 
    Main():QMainWindow(),m_pProcess1() 
{ 
}; 

~Main() 
     {}; 


public slots: 

void play() 

{ 
m_pProcess1.setProcessChannelMode(QProcess::MergedChannels); 
     m_pProcess1.start("mplayer -geometry 0:0 -vf scale=256:204 -noborder -af scaletempo /root/Desktop/spiderman.flv"); 

}; 

void playstop() 

{ 
m_pProcess1.setProcessChannelMode(QProcess::MergedChannels); 
     m_pProcess1.writeData("q",1); 


}; 

}; 

#endif