While playing music the media buttons on my headset works great. But if I pause and wait too long the previous media app I've used starts responding to media key presses instead of the the last active one, Spotify, as is expected.
As far as I can tell the Spotify app actively removes itself from the "preferred" media button responder list judging by the out put of "adb shell dumpsys audio".
While playing music with Spotify the stack looks like this:
1.5 years later and this still hasn't been fixed. 😕
Is it something with the API that is unclear? Or doesn't it work because of some bug in Android? Other media apps doesn't seem to have any problems using the AudioManager API for handling the preferred media button responder.