# Can anyone show me an example of API CoreListener?

**URL:** <https://discourse.mopidy.com/t/can-anyone-show-me-an-example-of-api-corelistener/779>\
**Category:** Misc\
**Created:** [June 17, 2015, 11:08am UTC](https://discourse.mopidy.com/t/can-anyone-show-me-an-example-of-api-corelistener/779 "2015-06-17T11:08:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Fabrizio\_Congia](https://avatars.discourse-cdn.com/v4/letter/f/cdc98d/32.png) [@Fabrizio\_Congia](https://discourse.mopidy.com/u/Fabrizio_Congia)\
**Post date:** [June 17, 2015, 11:08am UTC](https://discourse.mopidy.com/t/can-anyone-show-me-an-example-of-api-corelistener/779/1 "2015-06-17T11:08:36Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jodal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/jodal/32/2564_2.png) [@jodal](https://discourse.mopidy.com/u/jodal)\
**Post date:** [June 17, 2015, 11:28am UTC](https://discourse.mopidy.com/t/can-anyone-show-me-an-example-of-api-corelistener/779/2 "2015-06-17T11:28:45Z")

</div>

> <https://github.com/mopidy/mopidy-scrobbler/blob/master/mopidy_scrobbler/frontend.py#L37-L53>

---

<div class="post-metadata">

**Author:** ![Fabrizio\_Congia](https://avatars.discourse-cdn.com/v4/letter/f/cdc98d/32.png) [@Fabrizio\_Congia](https://discourse.mopidy.com/u/Fabrizio_Congia)\
**Post date:** [June 17, 2015, 1:47pm UTC](https://discourse.mopidy.com/t/can-anyone-show-me-an-example-of-api-corelistener/779/3 "2015-06-17T13:47:32Z")

</div>

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”.

---

<div class="post-metadata">

**Author:** ![jodal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/jodal/32/2564_2.png) [@jodal](https://discourse.mopidy.com/u/jodal)\
**Post date:** [June 18, 2015, 6:56am UTC](https://discourse.mopidy.com/t/can-anyone-show-me-an-example-of-api-corelistener/779/4 "2015-06-18T06:56:59Z")

</div>

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 [https://docs.mopidy.com/en/latest/extensiondev/](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](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.

---

<div class="post-metadata">

**Author:** ![jaedb](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.mopidy.com/jaedb/32/2340_2.png) [@jaedb](https://discourse.mopidy.com/u/jaedb)\
**Post date:** [September 8, 2016, 6:54am UTC](https://discourse.mopidy.com/t/can-anyone-show-me-an-example-of-api-corelistener/779/5 "2016-09-08T06:54:12Z")

</div>

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.
