Hooking into stop / play commands

Hello list,
i wonder if there is a way “hooking” into play / stop command of mopidy. I want to run a command if mopidy starts / stops playing. I looked into the extensions / API doc but i have no idea where to start.

Thanks and best,
B.

You can accomplish this by writing an extension and implementing the appropriate core listener method(s). See Can anyone show me an example of API CoreListener?

Or you could use the mpd interface’s idle functionality: https://bbs.archlinux.org/viewtopic.php?pid=581518#p581518

From something I’m working on at the moment

https://github.com/matgallacher/Mopidy-Favourite-Buttons/blob/master/mopidy_favourite_buttons/frontend.py

The hook itself

class MyNewCoreListener(pykka.ThreadingActor, core.CoreListener):

def __init__(self, config, core):
    super(MyNewCoreListener, self).__init__()
    self.core = core
	
def playback_state_changed(self, old_state, new_state):
    #Do something awesome when the music stops or starts!