Since High Sierra, Apple has introduced ‘universality’ to its set of media keys. All the absurdities aside, it means media keys are now open to work with any platform. So if you were planning to control iTunes or Spotify on the go, you may accidentally start playing a random video on a webpage instead.
You can simply click the following link and download the app called “Mac Media Key Fowarder” by Milan Toth. Codes, in case you are interested, are also available on the GitHub. It is a simple yet brilliant app that allows you to prioritize which app will receive the media key input first. The developer is distributing the app free, so please kindly consider donating as well.
As for what Apple has done with the media key, I can only see this as a crazy move. While media key is available on most laptops and quite common on desktop keyboards, they are not part of the standard input layout. In fact, even Mac has already removed all of its function keys with Touch Bar, more customizable touch screen based input system, quite obviously hinting its intention to free up these keys for customization. But this added behavior is quite a step backward; users simply cannot instinctively know what application will respond to the media keys anymore.
For better or worse, it appears Apple is pushing the media key to be more universal through out its platform. iOS already comes with unified media control on its control center, and it seems macOS will quickly follow suite. It then becomes the matter of how to streamline a control center of sort for Mac.