The setActionHandler() method of the MediaSession interface sets a handler for a media session action.
setActionHandler()
MDN Reference