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:
- make a frontend extension,
- with an actor class, and
- that actor class must subclass
mopidy.core.CoreListener
.
For step 1, please read https://docs.mopidy.com/en/latest/extensiondev/ in general.
For step 2 and 3, please read https://docs.mopidy.com/en/latest/extensiondev/#example-frontend for a specific example.
The Mopidy-Scrobbler extension also works as an example of all of this.