Use MPRIS/dbus media commands within Firefox on Linux
It's no longer necessary to use an extension these days. There's a standard D-Bus interface for media players: MPRIS, which is supported by recent Firefox versions. In Firefox versions before 81, it's still a bit experimental and needs to be enabled by toggling media.hardwaremediakeys.enabled
in about:config
; since Firefox 81 it's enabled by default and should work out of the box.
See this answer for more details.
I've found the extension web-media-controller the best implementation for this functionality. Just like the alternatives, it needs to run an executable in the background and interact with it through the native messaging protocol. This should be the superior choice since it's companion native messaging program - wmc-mpris
is written in C and is much faster then it's Python based alternatives.