50

I am on Ubuntu 16.04, I cannot play, pause, go to the next or the previous song in spotify. There are many answers but most are complicated, is there a simple solution that doesn't require a command line?

I have a Logitech bluetooth keyboard.

4
  • All I had to do is Close Google Chrome or any browser that had Youtube or any media playing, for my buttons to work with Spotify, then re-open browser
    – nicmwenda
    Commented Mar 4, 2020 at 6:00
  • @anadoba answer is AWESOME everyone. Check that first! Commented Apr 17, 2023 at 1:54
  • 1
    @digitalextremist Ok I accepted his answer to push it to the top, but I haven't tested it since the answer was posted 2 years after I asked the question.
    – Lynob
    Commented Apr 17, 2023 at 10:26
  • 1
    @Lynob very cool of you to do. I actually just provisioned a new workstation and came right back to this to use the advice again :) Nice of you to keep updating this excellent question you asked. Commented Apr 18, 2023 at 0:06

7 Answers 7

83

Here is another link i have found that help me and its the same solutions as k2shah mention it, but with more details.

Instead of downloading the spotify_control, you use the D-Bus commands. Before you add it as a new keyboard command, feel free to execute those commands.

Play/Stop

dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause

Next

dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Next

Previous

dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Previous

Once you validate the above commands, feel free to add them as Key Shortcut. For Ubuntu, "Settings > Devices > Keyboard" than add (+) and put the name and copy the commands, than put the keyboard shortcut.

TheLink

6
  • 1
    for next/prev worked like a charm, but for play/pause the audio play/pause key shortcut it doesn't work. If I remap it to 'super + ;' or other modifier + non-func key works. Any idea as to why? Commented Sep 13, 2019 at 5:24
  • Check if that map is already taken for something else.
    – IvanAK
    Commented Sep 13, 2019 at 11:06
  • 3
    Worked like a charm!
    – JavaRunner
    Commented Jul 15, 2020 at 19:14
  • On ubuntu 20.04 I was unable to set custom shortcuts to those keys since they were already used by other keyboard shortcuts (upon prompt for pressing keyboard combination nothing was happening when I was pressing Play/Stop button, not even the info line). I had to manually unset them using gsettings set command and then I was able to set it up. You can find the ones to unset in gsettings list-recursively (grep the result). Commented Jul 12, 2021 at 10:10
  • On Ubuntu 22 I don't find the + to add custom shortcuts. Commented Mar 19, 2023 at 7:05
38

There is a simple solution credit goes to this thread on Spotify forum, Thanks to schuellerf and rszabla. The solution is pretty simple and works on any Linux distribution.

  1. Download this file, extract it and make it executable chmod a+x spotify_control
  2. Place it anywhere you want, I'll assume that it is placed in Downloads folder
  3. Go to settings -> keyboard -> keyboard shortcuts -> custom shortcuts

enter image description here

  1. Add new shortcut by clicking the plus button, I'll override the default play/pause/next and previous keys because I only listen to music on spotify, If you need those shortcuts then assign different ones for Spotify

enter image description here

The command you see in the picture above is for 'play/pause' function

/home/your_username/Downloads/spotify_control playpause

The commands that are available

  1. /home/your_username/Downloads/spotify_control playpause
  2. /home/your_username/Downloads/spotify_control previous
  3. /home/your_username/Downloads/spotify_control next
  4. /home/your_username/Downloads/spotify_control play
  5. /home/your_username/Downloads/spotify_control stop

Please note that you have to do this

/home/your_username/Downloads/spotify_control playpause

Because

~/Downloads/spotify_control playpause

That won't work, at least not in Ubuntu 16.04, unity desktop, the shortcut manager doesn't seem to understand the tilde ~

5
  • 4
    this worked for me, thx! quick info of my system: ubuntu 16.04 and using an apple (wired)keyboard Commented Jan 4, 2019 at 18:02
  • What about "Don't Play This Song" shortcut for playlists? Commented Aug 23, 2019 at 11:36
  • 1
    Worked on 18.04 with spotify installed via snap. thanks
    – ibrahim
    Commented Mar 2, 2020 at 5:51
  • Its work on Fedora 34, but just play/pause command not worked for me? If any have a solution for me please tell me. Commented Jan 8, 2022 at 9:12
  • I found the solution, This keyboard shortcut set to for two command Commented Jan 8, 2022 at 9:23
21

The top-voted solutions are about adding a custom key mapping, which is kinda cumbersome, as you have to drop every other binding related to the Play/Pause key.
There's only one binding possible for a key so it means that your Play/Pause key stops working anywhere outside Spotify.

Initially, I wanted to do that, but Ubuntu settings didn't let me create a binding so the key was used/captured by something else on my system. It turned out that Chrome captures hardware media keys by default :)
You can disable this functionality by opening
chrome://flags/
and then disabling
Hardware Media Key Handling feature.

After doing so, your Play/Stop key along with Next and Previous keys are handled by Ubuntu itself again.
It fixed the issue for me. Now Spotify is the one to capture these keys.

This also happens on Firefox, you can access the option in:
about:config
Then, change
media.hardwaremediakeys.enabled to false

8
  • 3
    Worked like a charm! Thanks!
    – Mark D
    Commented Oct 8, 2020 at 16:35
  • 2
    This is it! The media keys are working but captured by chrome even if there is no player/youtube on it Commented Nov 24, 2020 at 21:20
  • 2
    This solution works for all chromium browsers, including Brave. Thanks!
    – ekl1pse
    Commented Jul 8, 2021 at 16:15
  • It also worked for me! Thanks Commented Sep 2, 2021 at 12:33
  • 1
    It works, thanks ! Too bad we have to choose between Spotify and Chrome...
    – adxl
    Commented Mar 16, 2022 at 15:28
7

All i had to do in Fedora is sudo dnf install playerctl

Anyway, it works in Ubuntu, no idea why such a basic functionality is missing here.

6

Considering the Aiphee Answer on ubuntu or Debian this works!

sudo apt install playerctl

Package info: utility to control media players via MPRIS https://packages.debian.org/buster/playerctl

2
  • 1
    Now you can add custom shortcut like playerctl play and first available player will play. I tested youtube + spotify.
    – Adrug
    Commented Jan 5, 2022 at 14:06
  • Doesn't work for me. After install I did playerctld daemon then the command playerctl -l returnd spotify. I've started Spotify, played a song, and tried Ctrl-Right Arrow to get next song, it didn't work. Am I missing smth ? Commented Mar 19, 2023 at 6:54
4

If you don't want to download a file and keep it around (for whatever reason) you can just assign the key to the command that's run in the file

I set up a new custom keybind

Name: Spotify Play/Pause

Command:

dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause

for the other commands just replace the PlayPause with Stop, Next, or Previous

0

You can call the D-Bus command directly.

  • Open System settings
  • Go to Shortcuts -> Custom Shortcuts
  • Select Edit -> New -> Global Shortcuts -> D-Bus Command ( the button is at bottom )
  • Set name : Spotify-Next
  • Bookmark Trigger: set shortcut by Your choice
  • Bookmark Action:
    • Remote application: org.mpris.MediaPlayer2.spotify
    • Remote object: /org/mpris/MediaPlayer2
    • Remote object: org.mpris.MediaPlayer2.Player.Next

For Previous use org.mpris.MediaPlayer2.Player.Previous

For Play/Pause uset org.mpris.MediaPlayer2.Player.PlayPause

You can test it with Call button More is

here

Thanks to IvanAK .

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .