audio-file-keys.lua
February 14, 2022 · View on GitHub
Automatically apply key bindings when playing audio files.
When playing audio files in a terminal, some key combinations may be
intercepted by the terminal and therefore made unavailable to mpv. For
example, Shift + Page Up/Down (seek forward/backward 10 min by default)
usually activates scrollback in most terminals.
A simple solution to this issue involves swapping those keys with others
(usually Page Up/Down, since audio files seldom include chapters).
Unfortunately, since key bindings are applied globally, this also affects
the playing of video files, where those other keys may be used more
frequently, making their remapping somewhat undesirable.
Wouldn't it be nice to be able to define a different set of key bindings for audio files? This is the purpose of this script.
USAGE
Simply drop this script in your scripts configuration directory (usually
~/.config/mpv/scripts/), and add some key bindings to the audio-file
input section in ~/.config/mpv/input.conf, such as:
# Have Page Up/Down emulate Shift + Page Up/Down for audio files
PGUP {audio-file} keypress Shift+PGUP
PGDWN {audio-file} keypress Shift+PGDWN
REQUIREMENTS
This script requires mpv version 0.10.0 or later.
NOTES
Technically, the trigger for this script is not directly based on the
contents of the file being played, but rather on the presence or
absence of a window. Therefore, an audio file with image attachments
will be considered as being a video file (unless audio-display=no).
This also means that this script can be forcibly disabled for all
files with --force-window, or forcibly enabled with --no-video.
(Note that setting vo=null will not have any effect, however.)
AUTHOR
Frédéric Brière (fbriere@fbriere.net)
Licensed under the GNU General Public License, version 2 or later.