Today I learned that we can control media players from commandline in Linux and Unix-like operating systems. You can play, pause, toggle between play and pause, increase/decrease volume, switch to next/previous media files, and stop the media playback in your media players. All from Terminal! Cool, yeah? Yes, it is. In this guide, we will learn to control the media players from the Terminal in Linux.
Control Media Players From Commandline In Linux
For the purpose of this, we will be using two simple utilities, namely Playerctl and OmniPause, to control the media players from command line.
Playerctl is a command line utility for controlling media files from Terminal. It will allow you to play, pause media files, switch to next or previous track, increase or decrease the volume, stop the playback etc. Using Playerctl, we can manage the all media players that implement the MPRIS D-Bus Interface Specification. Some of the popular media players that can be controlled using Playerctl are given below.
Playerctl is available in the official repositories of all modern Linux distributions. So, you can install it using the distribution's default package manager.
On Arch Linux:
$ sudo pacman -S playerctl
On Debian, Ubuntu and derivatives:
$ sudo apt-get install playerctl
$ sudo dnf install playerctl
$ sudo zypper install playerctl
If it is not available in the official repositories, you can manually compile and install it from using source. The latest source files are available in the releases page.
Control Media Players Using Playerctl
First, list all available players using command:
$ playerctl -l
$ playerctl --list-all
Sample output would be:
You can view the status of a player by mentioning its name with playerctl command:
$ playerctl status vlc Stopped
$ playerctl status smplayer Playing
As you can see, currently there are two players available (currently opened and running players) in my system. Vlc is stopped and smplayer is playing now.
To play the track , run:
$ playerctl play -p smplayer
$ playerctl play --player smplayer
If there were only one player is running, you don't have to use "-p" or "--player" switch. Playerctl will automatically play the track playing in the currently opened player.
To pause the currently playing track (assuming you have only one running player), run:
$ playerctl pause smplayer
To go to the next track, run:
$ playerctl next smplayer
To go the previous track, run:
$ playerctl previous smplayer
To toggle between play or pause, run:
$ playerctl play-pause smplayer
This option will resume the track if it is currently paused or play the track if it is currently being played now.
To stop the playback, run:
$ playerctl stop smplayer
To view the help section, run:
$ playerctl --help Usage: playerctl [OPTION…] COMMAND - Controller for MPRIS players For true players only: spotify, vlc, audacious, bmp, xmms2, and others. Help Options: -h, --help Show help options Application Options: -p, --player=NAME The name of the player to control (default: the first available player) -l, --list-all List the names of running players that can be controlled -V, --version Print version information and exit Available Commands: play Command the player to play pause Command the player to pause play-pause Command the player to toggle between play/pause stop Command the player to stop next Command the player to skip to the next track previous Command the player to skip to the previous track position [OFFSET][+/-] Command the player to go to the position or seek forward/backward OFFSET in seconds volume [LEVEL][+/-] Print or set the volume to LEVEL from 0.0 to 1.0 status Get the play status of the player metadata [KEY] Print metadata information for the current track. Print only value of KEY if passed
For more details, look at the project's GitHub page given at the end.
OmniPause is a simple python application to control media players via DBus. Unlike Playerctl, OmniPause is very new to the show and in early development stage. However it is fully functional and will do all of the same things as Playerctl.
OmniPause is written using Python, so you need to install the following dependencies first. These packages are available in the official repositories of all Linux distributions. So, you can install them using the default package manager.
After installing the prerequisites, git clone the project:
$ git clone https://github.com/mel00010/OmniPause.git
Go to the project's directory:
$ cd OmniPause/
And, run the following command to install it.
$ sudo make install
The above command will copy omnipause.py program to /usr/local/bin/omnipause.
Control Media Players using Omnipause
The usage is exactly same as Playerctl. Unlike Playerctl, Omnipause has limited functionality. The only available functions are:
To pause all running media players, run:
$ omnipause pause
To resume playback of media players paused by the program, run:
$ omnipause play
To stop all media players, run:
$ omnipause stop
To play the next track on all playing media players, run:
$ omnipause next
To play the previous track on all playing media players, run:
$ omnipause previous
To toggle the playback state of running media players, run:
$ omnipause toggle
As you can see, we can control all running media players using single command. It's that simple. Like Playerctl, It doesn't have any options to stop a specific player or increase/decrease volume. If you want to such options and more control over your media players, use playerctl program. Please note that Playerctl and OmniPause aren’t players, but CLI media player controllers.
Or maybe just use mplayer from the command line.
Yes. We can also use cmus. These are CLI-based players. Playerctl and OmniPause aren’t players, but CLI media player controllers.
I use Clementine, it has nice graphic controls.
That was a nice introduction. Helped me much.