Can anyone show me an example of API CoreListener?

Hi, I’m a Python Newbie and I wrote some code to collect info about the song that is being played on Mopidy.
The problem is that I need to know when the song starts. Can anyone show me an example of mopidy.core.CoreListener?
I need something like this:

On track_playback_started(tl_track)
    info()         # where info() is my function

Thank you

Thank you Jodal. I’m not sure if I understood the code. But mostly it fetchs informations about the song if I’m not wrong. But I don’t see where the code “knows” that the track is changed. That’s the only thing I need. Something that tells me “Hey, I started playing a new track, you can now run your code”.

That code knows that the track is changed because that method is only called by Mopidy when a track starts playback. For that call from Mopidy to your extension to happen, you must:

  1. make a frontend extension,
  2. with an actor class, and
  3. that actor class must subclass mopidy.core.CoreListener.

For step 1, please read in general.

For step 2 and 3, please read for a specific example.

The Mopidy-Scrobbler extension also works as an example of all of this.

1 Like

Hi @jodal thanks for that example, works a treat! I’m still getting my head around Python, so Mopidy-Scrobbler is a great example to work from.