Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

qt4

mplayer

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?

like image 889
yamuna mathew Avatar asked Mar 02 '11 06:03

yamuna mathew


1 Answers

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;
}
like image 52
Paul Merrill Avatar answered Sep 22 '22 20:09

Paul Merrill