I’m having issues with Mopidy. I’m trying to setup my pirate audio board so it immediately plays a song on boot. However, because I installed Musicbox as a WebClient for Mopidy ( using this command : sudo python3 -m pip install Mopidy-MusicBox-Webclient) I don’t have a setup.sh file that I can edit.
To make my question even clearer : how can I setup some sort of autostart on Mopidy?
Thanks in advance !
It’s difficult to answer, because many things depends on your particular system setup.
Basically what I would do is, at after booting :
- start mopidy
- use a command line client to add a song and play it
To autorun programs at boot, there are basically two solutions:
- run as the program a systemd service
- autologin a user and have that user autostart the program
Another thing to take into consideration is that mopidy likely takes some seconds to start, so you would have to add some delay between mopidy startup and the client commands.
My exact setup is :
-raspberry pi zero v1.3
-Pirate audio board
-sandisk ultra 16gb 10A1
-raspbian buster with desktop
-slightly modified script for pirate audio : instead of installing Iris install musicbox
(Link to the actual file : https://drive.google.com/file/d/16dBKwnT_sk8GPvq7YLioVXwKPNfg5FIr/view?usp=drivesdk)
Do you have any tutorial that would explain how to do what you think would be best?
Thanks and sorry for the late reply,
Ok so it appears you are running mopidy with a systemd service (you can see that with all the
systemctlcommands in the install script.
I thing the easiest way to go would be to create a custom service that would sleep for a while, then add a song and trigger playback. For this you need :
- install mopidy-mpd, and mpc
- Configure mpc to connect it with mopidy (i guess)
- Write and save a script like
mpc add "some song"
- Make the script executable:
chmod +x /path/to/script.sh
- Write a systemd service file like
- Save the service file in
- You can test if the service works using
systemctl start autoplay, which should trigger the song after 10 seconds (addapt to your needs)
- To enable the script and run it at each startup, run
systemctl enable autoplay in a terminal.
I might have forgotten a step or made some mistakes, but that should be the general idea.
Thanks a lot dude, it worked !
just had to add this to the service sript to be able to enable it :
Description=Automatically play a song on boot
while the [Unit] part is not required, the [Install] section is required to enable the service.
Thanks a lot for your time !!
Take care !
Nice, glad you made it work !
So I finally (almost) completed my project ! you can check it out here : https://github.com/G-a-v-r-o-c-h-e/PIpod-Nano
That is cool. I wanted to do something just like this but failed at the crucial step of actually doing it… so kudos to you! I like the idea of holding the button for longer to initiate a safe shutdown - that is neat. Have you considered suggesting they add this support to the https://github.com/pimoroni/mopidy-raspberry-gpio project?
Your instruction in the readme:
sudo apt-get install mpd-mopidy mpc -y
is wrong as there’s no such package as
mpd-mopidy. It should read:
sudo apt-get install mopidy-mpd mpc -y
(it’s already correct in your script).
You’ve got some typos in each of the occurrences of Pimoroni in the readme. And also note that the Raspberry Pi Foundation are very protective of their logo, you might have noticed you don’t see it used outside of their official stuff. If they see it they will, not unreasonably, ask you to remove it.
If you find your work to be used in my project and want a shout out, feel free to contact me.
Can Mopidy itself have a shout out?
EDIT: Are you working on a case or anything? Your README would be even better with some pictures!
Got it, I’ll give mopidy a shout out in the thanking section. Thanks for the corrections, I’ll make sure I edit this today !
Let’s hope that raspberry doesn’t see it then
I’m not working on a case currently, it is not my priority and I’m not even sure I’ll work on one someday… I’ll try to add some pictures if I find some relevant ones