How to force media key to control only music player on ubuntu mate 24.04?

I run ubuntu mate 24.04 on my machine, and I notice that now my media key on my logitech keyboard that usually only control strawberry music player, now will also control other media players that are open beside strawberry (like smplayer and youtube in this case).

Right now if I have both strawberry and smplayer up running, media key shortcut will only bind to smplayer, even if my mouse pointer is on-focus the strawberry music player.

Previously on ubuntu mate 22.04, media key (play/pause, stop, next, back) will only control exclusively music player. I like this old consistency behavior better than current one.

Question is how can i revert media key behavior back to the old behavior to 22.04?

I tried to replicate that:
I discovered that on 22.04 it controls a number of mediaplayers, at least Audacius , MPV and VLC on my rig.

  1. It only controls one player at a time
  2. It always controls the most recent opened and running player only. If that most recent opened player is closed, it switches to the next most recent opened player.

On 24.04 audacious and smplayer are both recognized.
MPV is not recognized unless mpv-mpris is installed.

Also here:

  1. It only controls one player at a time
  2. It always controls the most recent opened and running player only. If that most recent opened player is closed, it switches to the next most recent opened player.

Check the soundindicator to see which apps registered for mediakeys.

I haven't found a way yet to let the controls switch applications on the fly like you can on the 'sway' desktop.

( EDIT: It is a known issue )

If you want a certain player NOT to register to the mediakeys you have to disable either its dbus or mpris interface.
Unfortunately you can not blacklist them.
You can use dconf-editor to check which players have registered:

You can also give a preference to certain players:

2 Likes

I have a workaround for you:

Save the following code as '$HOME/.local/bin/mpris' and make it executable.

#!/bin/sh

busctl --user call org.mpris.MediaPlayer2.$1 \
/org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player $2 

This gives you the following command:

mpris playername action

Where playername and action are:

playername
	the name of the player to control
	like mpv or rhythmbox or audacious or vlc

action
	one of the following words (case sensitive!!)

	Play
	Pause
	PlayPause
	Next
	Previous
	Stop

This will enable you to define which player gets the mediakeys.

example:
mpris audacious Stop
mpris audacious Next
mpris mpv Play
mpris smplayer Previous
etc.

Assign these commands to your mediakeys by using mate-control-center -> shortcut-keys

The following workaround is less work and makes use of the command playerctl

examples:

playerctl --player=audacious stop
playerctl --player=mpv pause
playerctl --player=smplayer play

etc.

assign these commands to media-keys

3 Likes

a simple GUI solution:

I think I have a nice GUI workaroud that switches your controls between players:

(EDIT: corrected some typo's)

media-key-switcher

You need to install yad first (yad is a fork of zenity)

sudo apt install yad

After yad is installed, copy/paste the code below in a terminal and press enter:

cat<<TO_FILE > "$HOME/.local/share/applications/mpriswitch.desktop"
#!/usr/bin/env xdg-open

[Desktop Entry]
Version=1.0
Type=Application
Terminal=false
Name=MPRISwitch
Exec=bash -c 'killall playerctld ;wait; playerctld daemon; yad --title="MPRISwitch" --button="Next Player":"playerctld shift" --button="OK:0"'
Icon=/usr/share/pixmaps/faces/dice.jpg
TO_FILE 
chmod a+x "$HOME/.local/share/applications/mpriswitch.desktop"

You will now have an item 'MPRISwitch' in your menu
(You can add this to the desktop or the panel if you want)
Click on it an you'll see this:
media-key-switcher

The 'Next Player' button will switch the media-controls to the next player
'OK' will just close this dialog.

1 Like

In my case, i didn't experience this problem on 22.04, don't know why.

In my case, they even recognized youtube tabs that I open on firefox. This is annoying because I usually open alot of youtube tabs (4~6 YT tabs).

How do i do this? can you explain please..

I check dconf-editor and interestingly, my media keys also control telegram app at some point.

I just saw your next post, I'll try your workaround, I will post back here to report the result.

1 Like