MacOS High Sierra Media Key Enabler for iTunes and Spotify. You can prioritize which app you would like to control or you can go with the default behaviour which controls the running app. The app runs in the menu bar in the form of a subtle and beautiful black dot.
Download app - version 1.7 build 1 ( handles headphone buttons differently )
Apple just released High Sierra and it brought good things and annoying things : they changed the behaviour of the media controller keys, they no longer control itunes, they control the video playback in safari. This pissed off a lot of people including me, so I just created a menu bar app to proxy media key events to iTunes/Spotify while Apple fixes this. It doesn't support touchbar yet, only physical buttons.