以编程方式暂停视频播放器mpv

时间:2016-01-26 11:42:57

标签: linux

我想知道是否有办法向linux上正在运行的进程发送消息?

例如,是否可以通过编程方式“暂停”使用mpv启动的视频。

3 个答案:

答案 0 :(得分:14)

要远程控制mpv(例如从另一个终端会话),您也可以使用

选项启动它
--input-ipc-server=/tmp/mpvsocket

并通过发出如下命令来控制它:

echo '{ "command": ["set_property", "pause", true] }' | socat - /tmp/mpvsocket

有关(更多)更多详情,请参阅man mpv

编辑:另见mpv --list-properties

edit2:我发现“切换”暂停/播放的最简单方法是

{"command": ["cycle", "pause"]}

答案 1 :(得分:5)

kill -s STOP $(pidof mpv)kill -s CONT $(pidof mpv)

或更好:

xdotool key --window "$(xdotool search --class mpv)" p

键" P",默认设置为暂停视频。

答案 2 :(得分:3)

可以通过IPC控制mpv。从手册mpv(1)

--input-ipc-server=<filename>
       Enable the IPC support and create the listening socket at the given path.

       On  Linux and Unix, the given path is a regular filesystem path.
       On Windows, named pipes are used, so the path refers to the pipe namespace (\\.\pipe\<name>). If the \\.\pipe\ prefix is missing, mpv will add it automatically before creating the pipe, so --input-ipc-server=/tmp/mpv-socket and --input-ipc-server=\\.\pipe\tmp\mpv-socket are equivalent for IPC on Windows.

       See JSON IPC for details.

几个例子:

$ echo 'cycle pause'   | socat - /tmp/mpv-socket
$ echo 'playlist-prev' | socat - /tmp/mpv-socket
$ echo 'playlist-next' | socat - /tmp/mpv-socket

请参阅mpv(1)了解详情。

另见:

相关问题