Is there a command to stop and pause mplayer using the PId?
Asked Answered
C

4

5

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

For the pause button I used system("p"); but it is not working. I am able to store the process id of mplayer to a text file using system("ps -A |grep mplayer > PID.txt");.

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

Carbolated answered 2/3, 2011 at 6:2 Comment(0)
D
9

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;
}
Debbidebbie answered 2/3, 2011 at 7:14 Comment(0)
H
0

Not with a PID as far as I know. Check out slave mode (-slave) though. From man mplayer:

Switches on slave mode, in which MPlayer works as a backend for other programs. Instead of intercepting keyboard events, MPlayer will read commands separated by a newline (\n) from stdin.

You can control it perfectly that way.

Hilaria answered 2/3, 2011 at 6:50 Comment(0)
H
0

Yes use mplayer in the slave mode. That way you can pass commands to it from your program. Take a look at qmpwidget. Its open source and should solve all of your troubles. For commands check the mplayer site or search for mplayer slave mode commands.

Hufford answered 22/11, 2012 at 20:51 Comment(0)
L
0

I've written a similar program in QT which uses mplayer. I used QProcess to control mplayer.

Here is the some part of code. In the function playstop() you just send "q" and it exists the mplayer. If you send "p" it will pause mplayer.I hope it will be usefull for you.

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
Linnlinnaeus answered 25/2, 2013 at 12:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.