Mplayer slave mode description

Source: Internet
Author: User

Slave Mode Protocol

I. Introduction:

By default, mplayer obtains control information from the keyboard.

Mplayer also provides a more flexible control mode for playing control-Slave Mode

In slave mode, mplayer runs other programs in the background without intercepting keyboard events,

Mplayer reads a line break (\ n) separated command from the standard input.


Ii. Operations:

# Mplayer-input cmdlist

// A copy of all slave commands supported by mplayer is printed.

Method 1: Enter the control command on the console (for test)

Run mplayer-slave-Quiet <movie> and enter the slave command in the console window.
//-Slave start Mode
//-Quiet does not output redundant information


Common mplayer commands:

LoadFile string // The string parameter is the name of a song.
Volume 100 1 // set the volume to the center of the volume.
Mute1/0 // mute Switch
Pause // pause/cancel pause
Get_time_length // the return value is the length of the playback file, in seconds.
Seek value // The playback parameter value for the position of the file found forward is the number of seconds.
Get_percent_pos // percentage of returned files (0--100)
Get_time_pos // display the current position of the file in seconds. The floating point is used.
Volume <value> [ABS] // increase/decrease the volume, or set it to <value> If [ABS] is not zero
Get_file_name // print the current file name
Get_meta_album // print the metadata of the 'album 'of the current file
Get_meta_artist // print the metadata of the 'artist 'of the current file
Get_meta_comment // print the metadata of the 'comments' of the current file
Get_meta_genre // print the metadata of the 'stream' of the current file
Get_meta_title // print the metadata of the 'title' of the current file
Get_meta_year // print the metadata of the 'Year' of the current file

Method 2: input control commands from the famous Pipeline (FIFO) (used in Application Programming)

# Mkfifo </tmp/upload ofile>

# Mplayer-slave-input file = </tmp/movie ofile> <movie>

// You can write the slave command into the pipeline to implement the corresponding functions.

Example:The main process creates an unknown pipeline and a famous Pipeline.

1: open a sub-process

In the sub-process:
Start mplayer and set the parameters to communicate through the named pipeline;
Redirects the standard output of the sub-process to the write end of the unknown pipeline;
Mplayer reads the commands sent by the main process from the named pipeline;
The content sent by mplayer is sent to the unknown MPs queue. The parent process can read the message sent by mplayer through the read queue.

2: In the parent process:

Start two threads
The first thread constantly uses fgets to get a string command from the keyboard and write it into the named pipe.
The second thread cyclically checks whether the unknown pipeline has readable information and prints the information to the screen.

# Include <stdio. h> # include <stdlib. h> # include <unistd. h> # include <fcntl. h> # include <sys/STAT. h> # include <sys/types. h> # include <string. h>/********************** global variable definition area *********** * *****/INT fd_fifo; // create a famous pipeline, which is used to send the command int fd_pipe [2] to mplayer; // create an unknown pipeline for reading the command void * get_pthread (void * Arg) from mplayer) {char Buf [100]; while (1) {printf ("Please input you cmd:"); fflush (stdout); fgets (BUF, sizeof (BUF), stdin ); // get data from standard input Buf [s Trlen (BUF)] = '\ 0'; printf ("* % S * \ n", Buf); If (write (fd_fifo, Buf, strlen (BUF ))! = Strlen (BUF) perror ("write"); // write the command to the named pipe} void * print_pthread (void * Arg) {char Buf [100]; close (fd_pipe [1]); int size = 0; while (1) {size = read (fd_pipe [0], Buf, sizeof (BUF )); // read information from the write end of the unknown pipeline and print it on the screen. Buf [size] = '\ 0'; printf ("th MSG read form pipe is % s \ n ", buf) ;}} int main (INT argc, char * argv []) {int FD; char Buf [100]; pid_t PID; unlink ("/tmp/my_fifo "); // If the clear pipe exists, first Delete mkfifo ("/tmp/my_fifo", o_creat | 0666); perror ("mkfifo"); If (pipe (fd_pipe) <0) // create an unknown pipeline {perror ("pipe error \ n"); exit (-1);} pid = fork (); If (PID <0) {perror ("fork");} If (pid = 0) // The sub-process plays the mplayer {close (fd_pipe [0]); dup2 (fd_pipe [1], 1); // redirect the standard output of the sub-process to the write end fd_fifo = open ("/tmp/my_fifo", o_rdwr) of the pipeline; execlp ("mplayer ", "mplayer", "-slave", "-quiet", "-input", "file =/tmp/my_fifo", "juhuatai. MPG ", null) ;}else {pthread_t tid1; pthread_t tid2; fd_fifo = open ("/tmp/my_fifo ", o_rdwr); If (FD <0) perror ("open"); pthread_create (& tid1, null, get_pthread, null); // obtain control information pthread_create (& tid2, null, print_pthread, null) from the keyboard ); // print the information received from the unknown pipeline pthread_join (tid1, null); pthread_join (tid2, null);} return 0 ;}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.