终端命令控制标准音乐/视频播放器(播放/停止/下一个..)

终端命令控制标准音乐/视频播放器(播放/停止/下一个..)

在 Google 上搜索了一段时间后,我仍然无法(-.-)找到解决方案:

我想通过终端告知我的标准(如设置中所述)music/video player。但例如play/stop/next使用global commandand not命令。/usr/bin/banshee --next

这是我目前发现的:X86AudioNext(键盘键)、xmodmap(键盘键的组织)。

答案1

您的问题没有通用的答案,因为音乐播放器可以实现任何他们想要的功能。

但是,Ubuntu 的默认播放器都实现了 mpris2 接口(如果它们集成到声音菜单中)。因此,它们可以通过命令行进行控制。

可以使用的一个脚本如下:派姆普里斯

您可以像这样运行它:

mpris2-remote.py 播放

mpris2-remote.py 停止

mpris2-remote.py 下一步

如果你更喜欢更基本的东西,你可以看看 mpris2 定义这里

或者,您可以模拟 gnome 多媒体键,正如您在问题中所写。

答案2

这个问题很老了,但似乎得到很多的浏览量,所以我将分享另一个对我有用的解决方案。

安装该playerctl程序。它还提供了通过 MPRIS 控制播放器的方法,但可从 Ubuntu 存储库获取。

playerctl --help
Usage:
  playerctl [OPTION…] COMMAND - Controller for media players

  For players supporting the MPRIS D-Bus specification

Help Options:
  -h, --help                     Show help options

Application Options:
  -p, --player=NAME              A comma separated list of names of players to control (default: the first available player)
  -a, --all-players              Select all available players to be controlled
  -i, --ignore-player=IGNORE     A comma separated list of names of players to ignore.
  -f, --format                   A format string for printing properties and metadata
  -F, --follow                   Block and append the query to output when it changes for the most recently updated player.
  -l, --list-all                 List the names of running players that can be controlled
  -v, --version                  Print version information

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. If KEY is passed,
                          print only those values. KEY may be artist,title, album, or any key found in the metadata.
  open [URI]              Command for the player to open given URI.
                          URI can be either file path or remote URL.
  loop [STATUS]           Print or set the loop status.
                          Can be "None", "Track", or "Playlist".
  shuffle [STATUS]        Print or set the shuffle status.
                          Can be "On" or "Off".

相关内容