Getting event from MusicBox (Rapesberry pi)

i’m trying to write a simple script in python to catch the events from the MusicBox in a Rapesberry pi zero (like track_playback_started and so on).
As far as i know i need to implement an Actor for monitoring Mopidy.Core.Corelistener events. But I’m failing.
Anyone achieved that?
Thanks a lot.

Hi! You can try to use, which uses the websocket interface, and can be used to catch the mopidy events from a different script/process than mopidy itself (which I think is what you want to achieve)

There is barely no documentation (my apologies), but you can ask if you find any trouble.

Or use the python-mpd2 library. Something like:

from mpd import MPDClient
from select import select

client = MPDClient()
client.connect("localhost", 6600)
while True:
    if select([client], [], [], 0)[0]:

i tried your solution but i’m not sure to understand it 100%
How can i print in the shell the current song name?
Thanks a lot

I saw your solution, but unfortunately i couldn’t understand how to start the listener for events (I’m new to python language) since there’s no start method (as i espected).
Can you help me to build a very simple Listener for any events?
Thank a lot

The easiest way, I think, is using the bind_event method, where you provide the event name and the callback function for that event.

I was going to provide some example lines here, but since I wanted to try it first, I finally made a full example script. Please check:

Unluckily, there is no event loop in the code to make the program await only for events. It seems like a good addition, and I will look on how to implement it. By now, in my scripts I am using an infinite loop which can be stopped with ‘Ctrl-C’ (I know it’s ugly)

That’s exactly what i was looking for.
I tested all up on my raspberry p zero and worked like a charm!
Thank so much :slight_smile: