by
0
4
2,917
8
Top 1% !
Popular
Famous
Specified
Popularity: 4582nd place
Created
Modified May 25, 2015

Published on:

No tags for this snippet yet.
LanguageShell
LicenseMIT_X11
SourceGitHub

A small script for controlling mpv via the JSON IPC. Intended to resemble playerctl.

A small script for controlling mpv via the JSON IPC. Intended to resemble playerctl.: 
mpvctl
Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/523011/A-small-script-for-controlling-mpv-via-t?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
#!/usr/bin/env bash # This script requires: # - that the directory $HOME/.mpv exist # - that you start mpv with the unix socket feature pointing at that directory # I recommend an alias in your .bashrc or equivalent file: # alias mpv="mpv --input-unix-socket=$HOME/.mpv/socket" socket="$HOME/.mpv/socket" command() { # JSON preamble. local tosend='{ "command": [' # adding in the parameters. for arg in "$@"; do tosend="$tosend \"$arg\"," done # closing it up. tosend=${tosend%?}' ] }' # send it along and ignore output. # to print output just remove the redirection to /dev/null echo $tosend | socat - $socket &> /dev/null } [ "$1" = "next" ] && command 'playist_next' [ "$1" = "previous" ] && command 'playlist_prev' [ "$1" = "stop" ] && command 'quit' [ "$1" = "play-pause" ] && command 'cycle' 'pause' [ "$1" = "pause" ] && command 'set' 'pause' 'yes' [ "$1" = "play" ] && command 'set' 'pause' 'no'
If you want to be updated about similar snippets, Sign in and follow our Channels