Is there a command to stop and pause mplayer using PId?

I play mplayer from my Qt application using the play button. I have two buttons called pause and stop. For the play button, I used system ("mplayer "+s.toAscii()+"&");where sis the playlist.

For the pause button I used system("p");, but it does not work. I can save the mplayer process id to a text file using system("ps -A |grep mplayer > PID.txt");.

Is there any command to stop and pause mplayer using PId?

+5
source share
4 answers

What you probably want is the MPlayer sub- mode of operation , which makes it easy to transfer commands from another program. You can start MPlayer in this mode by providing it with a command line command -slavewhen it starts.

In this mode, MPlayer ignores its standard input bindings and instead accepts another dictionary of text commands that can be sent one at a time, separated by newlines. For a complete list of supported commands, run mplayer -input cmdlist.

Since you marked the question as Qt, I assume you are using C ++. Here's an example C program demonstrating how to use slave MPlayer 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;
}
+6
source

PID, . (-slave). mplayer:

, MPlayer . MPlayer , (\n) stdin.

.

0

mplayer . , . qmpwidget. . mplayer maveer slave mode.

0

QT, mplayer. 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
0

All Articles