Xubuntu Spotify上的Windows播放/暂停键

我试图找出如何设置我的媒体键以在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 

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

  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 
  2. 退出并重新登录(或者您可以关闭任何可能拦截多媒体密钥的应用,在我的实例中,这意味着Google Chrome)

它适用于两台不同的计算机:运行Xubuntu 14.04的Dell Optiplex和运行Xubuntu 16.04的Thinkpad。

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

安装xbindkeys。

 $ sudo apt-get install xbindkeys 

为xbindkeys创建默认配置文件。

 $ xbindkeys --defaults > ~/.xbindkeysrc 

编辑xbindkeys的配置文件。

 $ nano ~/.xbindkeysrc 

添加以下行:

 "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 

键绑定的其他示例:

 # 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 

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

 $ xbindkeys 

现在,当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