Xubuntu Spotify 上的 Windows 播放/暂停键

Chr*_*ull 5 xubuntu shortcut-keys spotify

我试图找出如何设置我的媒体密钥以在 Xubuntu 14.04 上使用 Spotify。我尝试将 Spotify 设置为我的默认音乐播放器。我认为这将是一项简单的任务,但我想不出一种方法来做到这一点,并且不确定它是否会起作用。

这是xev我的播放/暂停按钮的输出(我不知道这意味着什么,但你去吧:

    KeyPress event, serial 37, synthetic NO, window 0x4600001,
    root 0x497, subw 0x0, time 2164738, (756,-274), root:(1350,51),
    state 0x0, keycode 172 (keysym 0x1008ff14, XF86AudioPlay), same_screen YES,
    XLookupString gives 0 bytes: 
    XmbLookupString gives 0 bytes: 
    XFilterEvent returns: False

    KeyRelease event, serial 37, synthetic NO, window 0x4600001,
    root 0x497, subw 0x0, time 2164823, (756,-274), root:(1350,51),
    state 0x0, keycode 172 (keysym 0x1008ff14, XF86AudioPlay), same_screen YES,
    XLookupString gives 0 bytes: 
    XFilterEvent returns: False
Run Code Online (Sandbox Code Playgroud)

bma*_*pin 5

Xfce/Xubuntu 实际上已经包含将多媒体键映射到自定义命令的功能,因此无需安装任何额外的软件包或创建任何文件即可完成此操作:

  1. 绑定键
    (这也可以通过设置手动完成?键盘应用程序快捷方式

    xfconf-query -c xfce4-keyboard-shortcuts -p /commands/custom/XF86AudioPlay -s "dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause" -n -t string
    xfconf-query -c xfce4-keyboard-shortcuts -p /commands/custom/XF86AudioNext -s "dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Next" -n -t string
    xfconf-query -c xfce4-keyboard-shortcuts -p /commands/custom/XF86AudioPrev -s "dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Previous" -n -t string
    
    Run Code Online (Sandbox Code Playgroud)
  2. 注销并重新登录(或者您可以关闭任何可能拦截多媒体密钥的应用程序,在我的例子中这意味着谷歌浏览器)

它在两台不同的计算机上对我有用:运行 Xubuntu 14.04 的 Dell Optiplex 和运行 Xubuntu 16.04 的 Thinkpad。

我还在这里添加了一些额外的注释以及更详细的故障排除等:https : //gist.github.com/bmaupin/acc566ff44a8ebf20c2aa2707789e6ea


小智 1

安装 xbindkeys。

$ sudo apt-get install xbindkeys
Run Code Online (Sandbox Code Playgroud)

为 xbindkeys 创建默认配置文件。

$ xbindkeys --defaults > ~/.xbindkeysrc
Run Code Online (Sandbox Code Playgroud)

编辑 xbindkeys 的配置文件。

$ nano ~/.xbindkeysrc
Run Code Online (Sandbox Code Playgroud)

添加这些行:

"dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause"
XF86AudioPlay <-- or the key(s) you want

"dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Stop"
XF86AudioStop <-- or the key(s) you want
Run Code Online (Sandbox Code Playgroud)

键绑定的其他示例:

# spotify controls
"dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause"
  F8 <-- key assigned

"dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Next"
  F9 <-- key assigned
Run Code Online (Sandbox Code Playgroud)

运行 xbindkeys 查看是否一切正常:

$ xbindkeys
Run Code Online (Sandbox Code Playgroud)

现在,当 Spotify 运行时,按播放/暂停键将使您的音乐开始或停止。

您需要将其设置xbindkeys为启动时自动运行。在 Ubuntu 上,System -> Preferences -> Startup Applications.

完毕!

来源:https://shkspr.mobi/blog/2011/12/linux-spotify-keybindings/ https://gist.github.com/jbonney/5743509#file-spotify_keybindings-L1