input.conf file and use the valid command cycle-values with the property playlist-pos, specifying the direction as -1. This configuration allows you to jump to the previous file in your playlist or directory sequence using a custom keyboard shortcut, effectively reversing the default forward navigation behavior without relying on incorrect syntax like cycle backwards.
Understanding MPV Input Configuration
MPV handles all user interactions through its input configuration system. Unlike many graphical applications that offer a settings menu for every feature, mpv relies on a text-based configuration file named input.conf. This file is located in the mpv configuration directory, which varies by operating system. On Linux and macOS, this is typically ~/.config/mpv/input.conf, while on Windows it is found at %APPDATA%\mpv\input.conf.
The structure of each line in this file follows a simple pattern: KEY COMMAND [args]. The key defines the physical button or combination on your keyboard, and the command tells mpv what action to perform. By adding a new line to this file, you can override default bindings or add entirely new functionality. It is crucial to understand that mpv commands are case-sensitive and specific. Using generic terms or incorrect command names will result in errors or ignored inputs.
The Correct Command Syntax
A common misconception among users is that there is a built-in command called "cycle backwards." However, mpv does not recognize this phrase. Instead, you must use the cycle-values command combined with the playlist-pos property. The playlist-pos property represents the index of the currently playing file in the playlist, starting from zero. By cycling this value in the negative direction, you move to the previous item.
The correct syntax is:
KEY cycle-values playlist-pos -1
Here, KEY is the shortcut you wish to assign (for example, p or P). The cycle-values command iterates through the possible values of the specified property. The argument -1 instructs mpv to decrement the playlist position. If you are at the first file (position 0), pressing the key will wrap around to the last file in the playlist, creating a seamless loop. This approach is robust because it works regardless of how many files are in your playlist or whether they are local files or remote streams.
Step-by-Step Implementation
To implement this feature, follow these precise steps. First, locate your mpv configuration directory. You can find the exact path by running mpv --print-path=scriptdir in your terminal or command prompt, although the standard paths mentioned earlier work for most users. Once you have located the directory, open or create the input.conf file. If the file does not exist, create it as a plain text file.
- Open
input.confin your preferred text editor. - Add a new line at the end of the file with the syntax discussed above. For example, to use the 'P' key (shift+p), you would write:
P cycle-values playlist-pos -1. - Save the file and close the editor.
- Restart mpv or reload the configuration by pressing
Ctrl+Rinside the player if it is already running.
After restarting, test the key. When you press your chosen shortcut, the player should jump to the previous file. If nothing happens, check the mpv console output for error messages. Common issues include typos in the command name or incorrect file permissions preventing mpv from reading the configuration.
Alternative Navigation Methods
If you prefer not to modify the configuration file, you can also use the built-in prev and next commands, though these behave slightly differently. The prev command jumps to the previous file but does not support wrapping around from the first to the last file in the same seamless manner as cycle-values with playlist-pos. Therefore, for a true backward cycle effect, the cycle-values method is superior. Additionally, you can explore other input configurations to enhance your workflow. For instance, if you are interested in optimizing your overall media player experience, you might look into related topics such as FFmpeg Causing Sort Conflict with MPV: Script Issue to ensure your environment is stable.
Troubleshooting Common Issues
Sometimes, even after adding the correct line, the hotkey may not work. The first thing to check is whether another configuration file is overriding your changes. MPV loads configurations from multiple locations, including mpv.conf and scripts. Ensure that no script is binding the same key to a different action. You can verify active bindings by pressing ? in mpv, which displays a list of current key bindings. Look for your chosen key in this list; if it shows a different command, you need to either change your key choice or remove the conflicting binding.
Another potential issue is the scope of the playlist. If you are playing a single file without a playlist, playlist-pos remains at 0. In this scenario, pressing the backward key will wrap to the last item in the internal playlist, which might be empty or contain only the current file. To avoid confusion, ensure you have loaded a directory or multiple files into mpv before testing the backward cycle feature. This ensures that the playlist has multiple positions to cycle through.
Frequently Asked Questions
What is the difference between prev and cycle-values playlist-pos?
The prev command simply moves to the previous index without wrapping around from the start to the end. In contrast, cycle-values playlist-pos -1 wraps around seamlessly, allowing you to go from the first file to the last. This makes it ideal for continuous playback sessions where you want to revisit earlier files easily.
Can I use a mouse button for this backward cycle?
Yes, you can bind any supported mouse button in input.conf. Use the format MBTN_BACK or MBTN_FORWARD instead of a keyboard key. For example, MBTN_BACK cycle-values playlist-pos -1 would make the back mouse button trigger the backward cycle. This provides an alternative navigation method for users who prefer mouse gestures.
Why does my hotkey not work when I press it?
This usually happens due to a typo in the command name or a conflict with another binding. Check the mpv console for errors and ensure you used cycle-values and playlist-pos exactly. Also, verify that no other script or configuration is intercepting the key. Pressing ? in mpv helps identify existing bindings.
Does this work with network streams?
Yes, as long as the streams are added to the playlist. If you load multiple URLs into mpv, they become part of the playlist, and playlist-pos tracks their order. Navigating backward will switch to the previous URL in the list. However, if you are streaming a single live feed, this feature is less relevant since there is no prior item to cycle to.
How do I reset my input.conf to defaults?
To revert to default bindings, simply delete or rename your input.conf file. MPV will then fall back to its built-in defaults. Be aware that this removes all custom shortcuts you have created, so keep a backup if you want to restore them later. You can also clear specific bindings by commenting out lines with a # character at the start.