音乐爱好者们好! 今天我了解到我们可以在类 Unix 操作系统中通过命令行控制媒体播放器。 您可以播放、暂停、在播放和暂停之间切换、增大/减小音量、切换到下一个/上一个媒体文件,以及停止媒体播放器中的媒体播放。 全部来自终端! 酷,是吗? 是的。 在本指南中,我们将学习在 Linux 中从终端控制媒体播放器。
在 Linux 中从命令行控制媒体播放器
为此,我们将使用两个简单的实用程序,即 播放器 和 全能暂停从命令行控制媒体播放器。
1. Playerctl
播放器 是一个命令行实用程序,用于从终端控制媒体文件。 它将允许您播放、暂停媒体文件、切换到下一首或上一首曲目、增大或减小音量、停止播放等。使用 Playerctl,我们可以管理实现 MPRIS D-Bus 接口规范。 下面给出了一些可以使用 Playerctl 控制的流行媒体播放器。
- 大胆,
- 骨肉瘤,
- Spotify,
- Mplayer/SMplayer,
- 超大容量、
- Xmms2。
安装 Playerctl
Playerctl 在所有现代 Linux 发行版的官方存储库中都可用。 因此,您可以使用发行版的默认包管理器安装它。
在 Arch Linux 上:
$ sudo pacman -S playerctl
在 Debian、Ubuntu 和衍生产品上:
$ sudo apt-get install playerctl
在 Fedora:
$ sudo dnf install playerctl
在 openSUSE 上:
$ sudo zypper install playerctl
如果官方存储库中没有它,您可以使用源代码手动编译和安装它。 最新的源文件可在 发布页面.
用法
首先,使用命令列出所有可用的玩家:
$ playerctl -l
或者,
$ playerctl --list-all
示例输出为:
vlc smplayer
您可以通过使用 playerctl 命令提及其名称来查看播放器的状态:
$ playerctl status vlc Stopped
$ playerctl status smplayer Playing
如您所见,我的系统中目前有两个可用的播放器(当前打开和运行的播放器)。 Vlc 已停止,现在正在播放 smplayer。
要播放曲目,请运行:
$ playerctl play -p smplayer
或者,
$ playerctl play --player smplayer
如果只有一个播放器在运行,则不必使用“-p”或“–player”开关。 Playerctl 会自动播放当前打开的播放器中正在播放的曲目。
要暂停当前播放的曲目(假设您只有一个正在运行的播放器),请运行:
$ playerctl pause smplayer
要转到下一个曲目,请运行:
$ playerctl next smplayer
要走上一条轨道,请运行:
$ playerctl previous smplayer
要在播放或暂停之间切换,请运行:
$ playerctl play-pause smplayer
如果当前暂停,此选项将恢复曲目,如果当前正在播放,则播放曲目。
要停止播放,请运行:
$ playerctl stop smplayer
要查看帮助部分,请运行:
$ 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
有关更多详细信息,请查看最后给出的项目的 GitHub 页面。
2. 全能暂停
全能暂停 是一个简单的 python 应用程序,用于通过 DBus 控制媒体播放器。 与 Playerctl 不同,OmniPause 对节目来说是非常新的并且处于早期开发阶段。 然而,它功能齐全,可以做与 Playerctl 相同的所有事情。
安装 Omnipause
OmniPause 是使用编写的 Python,所以需要先安装以下依赖。 这些包在所有 Linux 发行版的官方存储库中都可用。 因此,您可以使用默认的包管理器安装它们。
- 蟒蛇2
- dbus-python
安装先决条件后, git clone 项目:
$ git clone https://github.com/mel00010/OmniPause.git
进入项目目录:
$ cd OmniPause/
并且,运行以下命令来安装它。
$ sudo make install
上面的命令会将omnipause.py程序复制到 /usr/local/bin/omnipause.
用法
用法与 Playerctl 完全相同。 与 Playerctl 不同,Omnipause 的功能有限。 唯一可用的功能是:
- 玩,
- 暂停,
- 下一个,
- 以前的,
- 切换,
- 停止。
要暂停所有正在运行的媒体播放器,请运行:
$ omnipause pause
要恢复播放被程序暂停的媒体播放器,请运行:
$ omnipause play
要停止所有媒体播放器,请运行:
$ omnipause stop
要在所有正在播放的媒体播放器上播放下一首曲目,请运行:
$ omnipause next
要在所有正在播放的媒体播放器上播放上一首曲目,请运行:
$ omnipause previous
要切换正在运行的媒体播放器的播放状态,请运行:
$ omnipause toggle
如您所见,我们可以使用单个命令控制所有正在运行的媒体播放器。 就是这么简单。 与 Playerctl 一样,它没有任何选项可以停止特定播放器或增加/减少音量。 如果您想要这样的选项并更多地控制您的媒体播放器,请使用 playerctl 程序。 请注意 Playerctl 和 OmniPause 不是播放器,而是 CLI 媒体播放器控制器。
资源:
感谢您的光临!
帮助我们帮助您:
- 订阅我们的电子邮件通讯: 立即注册
- 支持 OSTechNix: 通过贝宝捐款
- 下载免费的电子书和视频: TradePub 上的 OSTechNix
- 联系我们: 红迪网 | Facebook | Twitter | 领英 | RSS订阅
祝你有美好的一天!!