[MX Player] leo46:
More info: if I quit the app, I get this message:

09-20 07:23:44.851 1248 2354 D MediaSessionService: Media button session is changed to null

So it appears based on what app has forground or is playing audio, Android knows to which app it should send the event.

Here is what happens when MXPlayer has focus and is playing a video:

09-20 07:23:20.859 1248 15263 D MediaSessionService: Sending KeyEvent { action=ACTION_UP, keyCode=KEYCODE_MEDIA_PLAY, scanCode=0, metaState=0, flags=0x0, repeatCount=0, eventTime=0, downTime=0, deviceId=-1, source=0x0, displayId=0 } to com.mxtech.videoplayer.pro/MediaSessionHelper-com.mxtech.videoplayer.pro (userId=0)
09-20 07:23:20.860 1248 15263 I MediaSessionService: tempAllowlistTargetPkgIfPossible callingPackage:com.google.android.googlequicksearchbox targetPackage:com.mxtech.videoplayer.pro reason:action=ACTION_UP;code=KEYCODE_MEDIA_PLAY [WIU] [FGS]
09-20 07:23:27.350 1248 2015 D MediaSessionService: Sending KeyEvent { action=ACTION_DOWN, keyCode=KEYCODE_MEDIA_PLAY, scanCode=0, metaState=0, flags=0x0, repeatCount=0, eventTime=0, downTime=0, deviceId=-1, source=0x0, displayId=0 } to com.mxtech.videoplayer.pro/MediaSessionHelper-com.mxtech.videoplayer.pro (userId=0)
09-20 07:23:27.350 1248 2015 I MediaSessionService: tempAllowlistTargetPkgIfPossible callingPackage:com.google.android.googlequicksearchbox targetPackage:com.mxtech.videoplayer.pro reason:action=ACTION_DOWN;code=KEYCODE_MEDIA_PLAY [WIU] [FGS]
09-20 07:23:27.355 1248 3831 D MediaSessionService: Sending KeyEvent { action=ACTION_UP, keyCode=KEYCODE_MEDIA_PLAY, scanCode=0, metaState=0, flags=0x0, repeatCount=0, eventTime=0, downTime=0, deviceId=-1, source=0x0, displayId=0 } to com.mxtech.videoplayer.pro/MediaSessionHelper-com.mxtech.videoplayer.pro (userId=0)
09-20 07:23:27.356 1248 3831 I MediaSessionService: tempAllowlistTargetPkgIfPossible callingPackage:com.google.android.googlequicksearchbox targetPackage:com.mxtech.videoplayer.pro reason:action=ACTION_UP;code=KEYCODE_MEDIA_PLAY [WIU] [FGS]
09-20 07:23:30.695 1248 2015 D MediaSessionService: Sending KeyEvent { action=ACTION_DOWN, keyCode=KEYCODE_MEDIA_PLAY, scanCode=0, metaState=0, flags=0x0, repeatCount=0, eventTime=0, downTime=0, deviceId=-1, source=0x0, displayId=0 } to com.mxtech.videoplayer.pro/MediaSessionHelper-com.mxtech.videoplayer.pro (userId=0)
09-20 07:23:30.695 1248 2015 I MediaSessionService: tempAllowlistTargetPkgIfPossible callingPackage:com.google.android.googlequicksearchbox targetPackage:com.mxtech.videoplayer.pro reason:action=ACTION_DOWN;code=KEYCODE_MEDIA_PLAY [WIU] [FGS]
09-20 07:23:30.706 1248 2015 D MediaSessionService: Sending KeyEvent { action=ACTION_UP, keyCode=KEYCODE_MEDIA_PLAY, scanCode=0, metaState=0, flags=0x0, repeatCount=0, eventTime=0, downTime=0, deviceId=-1, source=0x0, displayId=0 } to com.mxtech.videoplayer.pro/MediaSessionHelper-com.mxtech.videoplayer.pro (userId=0)
09-20 07:23:30.708 1248 2015 I MediaSessionService: tempAllowlistTargetPkgIfPossible callingPackage:com.google.android.googlequicksearchbox targetPackage:com.mxtech.videoplayer.pro reason:action=ACTION_UP;code=KEYCODE_MEDIA_PLAY [WIU] [FGS]
09-20 07:23:32.109 1248 2015 D MediaSessionService: Sending KeyEvent { action=ACTION_DOWN, keyCode=KEYCODE_MEDIA_PAUSE, scanCode=0, metaState=0, flags=0x0, repeatCount=0, eventTime=0, downTime=0, deviceId=-1, source=0x0, displayId=0 } to com.mxtech.videoplayer.pro/MediaSessionHelper-com.mxtech.videoplayer.pro (userId=0)
09-20 07:23:32.110 1248 2015 I MediaSessionService: tempAllowlistTargetPkgIfPossible callingPackage:com.google.android.googlequicksearchbox targetPackage:com.mxtech.videoplayer.pro reason:action=ACTION_DOWN;code=KEYCODE_MEDIA_PAUSE [WIU] [FGS]
09-20 07:23:32.114 1248 2015 D MediaSessionService: Sending KeyEvent { action=ACTION_UP, keyCode=KEYCODE_MEDIA_PAUSE, scanCode=0, metaState=0, flags=0x0, repeatCount=0, eventTime=0, downTime=0, deviceId=-1, source=0x0, displayId=0 } to com.mxtech.videoplayer.pro/MediaSessionHelper-com.mxtech.videoplayer.pro (userId=0)
09-20 07:23:32.119 1248 2015 I MediaSessionService: tempAllowlistTargetPkgIfPossible callingPackage:com.google.android.googlequicksearchbox targetPackage:com.mxtech.videoplayer.pro reason:action=ACTION_UP;code=KEYCODE_MEDIA_PAUSE [WIU] [FGS]