How to auto play a playlist after reset

Hello, I’ve got my Volumio Raspberry Pi system working, but now I would like to add a feature.

Every night when we feed our baby daughter we play the same playlist - about 30 tracks on shuffle.

The feature i want to add is a physical button to the Pi which will load that playlist and start playing it.

I though that the easiest way would be to add a reset button to the pi, then have the pi always start up playing that playlist.
(alternative is to add a gpio button: cl.cam.ac.uk/projects/raspb … _switches/ which replaces the current playlist.)

I’m fine with soldering and adding buttons, but I don’t have a clue where to start with hacking the code to start autoplaying a playlist.
Does anyone know how to? :question:

Many thanks
Drew :smiley:

Hello,

if you want to start volumio to play a playlist after boot you can edit /etc/rc.local.

sudo nano /etc/rc.local

The following commands at the end of the rc.local could help:

sudo mpc clear & sudo mpc random on & sudo consume off & sudo mpc load "playlist" & sudo mpc play &

mpc clear >> resets current playlist
mpc random >> random play on /off
mpc consume >> playlist entries will delete if played (or not)
mpc play >> starts playing

A expert could do it more cleanly of sure!

All commands could also be started in a python script via GPIO. There are some howtos in the web that describes how to start a script by press a button wired to the gpio pins.

Tobbes

Hi,

maybe the playlist directory for volumio and mpc is not the same.
If your playlist will not play - try to store it here:
/var/lib/mpd/playlists/

Tobbes

Hi Tobbes, many thanks for your help.
If found one small bug, I think that there should be an “mpc” before Consume

sudo mpc clear & sudo mpc random on & sudo mpc consume off & sudo mpc load "playlist" & sudo mpc play &

And 2 bigger problems:
1 My pi seems to reset the rc.local file after every reboot, so that this script dissapears after one restart. ???
2 I’m not quite clear on how to enter the specific playlist, into the script. :unamused:

Thanks
Drew

rc.local is shadowed in /var/www/_OS_SETTINGS/etc and will be checked and replaced during reboot if changed
once you are sure your rc.local is working, you can put a copy in /var/www/_OS_SETTINGS/etc

OR

you can edit /var/www/inc/player_lib.php to turn off the checking and replacement

Hello Drew,

yes you are right:

sudo mpc consume off &

You could place a playlist in /var/lib/mpd/playlists/

sudo nano /var/lib/mpd/playlists/babylist.pls

The file must look like:

[playlist]
NumberOfEntries=3
File1=http://mp3.planetradio.de/planetradio/hqlivestream.mp3
Title1=Planet Radio
File2=/path/to/the/mp3file.mp3
Title2=mp3file.mp3
File3=/path/to/next/file.mp3
Title3=file.mp3

Readable for all users:

sudo chmod 644 /var/lib/mpd/playlists/babylist.pls

sudo mpc update Can also update over volumio GUI

sudo mpc load babylist.pls
sudo mpc play

Tobbes

Hey that’s Great Tobbes, Thank you so much for your help.
I will try to find the time to try it out on the next few days.
And report back with how I got on.
Drew

Thanks for the heads up on how to do this.

I’m sure my stumbling approach has some holes in it, but here’s what I did to get it to work:

First, I used MPDroid to make a playlist.
I found that playlist in the location identified above:
/var/lib/mpd/playlists/one.m3u (not .pls in this case)

I updated the library (by UI or command line, I’d think). This seemed to be what was necessary to make the playlist just “play” without having to indicate where to find it.

sudo mpc update

I tested the rc.local by running it from the command line while watching the web “Playback” screen. Which shows if there’s any errors from the command line and shows me if it’s working while watching the UI. /etc/rc.local
It got some errors and didn’t always seem to take, though it all worked if I did it line-by-line from the command line. So, on a hunch, I added some delays and it works now. I copied it to the “shadow” location so it is permanently loaded (after making a backup of the shadow rc.local).

sudo cp /var/www/_OS_SETTINGS/etc/rc.local /var/www/_OS_SETTINGS/etc/rc.local.OLD sudo cp /etc/rc.local /var/www/_OS_SETTINGS/etc
Here’s the rc.local that’s working:

sudo mpc clear & sudo sleep 2 sudo mpc volume 93 & sudo mpc random off & sudo mpc consume off & sudo sleep 2 sudo mpc load "one" & sudo sleep 5 mpc play &
I restarted the system (sudo reboot) and watched the UI lose connection, then eventually find it again, have no playlist, load one and then play.

BTW, this .m3u playlist is VERY simple, unlike the .pls sample above. I tried copying it to every SMB-shared location to see if it would work. I /really/ expected it to work in the WebRadio folder, but it didn’t. To hand-edit it, I just copied it to the USB location, edited it and copied it back to the normal location.

USB/Hell Freezes Over (1994)/01 - Get Over It.mp3 USB/Hell Freezes Over (1994)/02 - Love Will Keep Us Alive.mp3 USB/Hell Freezes Over (1994)/03 - The Girl From Yesterday.mp3 USB/Hell Freezes Over (1994)/04 - Learn To Be Still.mp3 USB/Hell Freezes Over (1994)/05 - Tequila Sunrise.mp3 USB/Hell Freezes Over (1994)/06 - Hotel California.mp3 USB/Hell Freezes Over (1994)/07 - Wasted Time.mp3 USB/Hell Freezes Over (1994)/08 - Pretty Maids All In A Row.mp3 USB/Hell Freezes Over (1994)/09 - I Can't Tell You Why.mp3 USB/Hell Freezes Over (1994)/10 - New York Minute.mp3 USB/Hell Freezes Over (1994)/11 - The Last Resort.mp3 USB/Hell Freezes Over (1994)/12 - Take It Easy.mp3 USB/Hell Freezes Over (1994)/13 - In The City.mp3 USB/Hell Freezes Over (1994)/14 - Life In The Fast Lane.mp3 USB/Hell Freezes Over (1994)/15 - Desperado.mp3
It’s that simple.

Let me know if I missed any steps or typo’d anything.

I just found this thread because I’d like to autostart mpd after boot. so probably someone can help.

If I play some webradio with volumio 1.55 itwill be started again after a reboot. but if I play music form my NAS, it’s not working.
I tried to add “/usr/bin/mpc play” to rc.local file but without success. Can anyone help?

I have still this problem. no hint?

After a lot of fiddling with /etc/rc.local I realized that the NAS is mounted only after my commands in rc.local were executed. A sleep may help, but rc.local is killed if you sleep to long … argh, nasty!

Instead I decided to hardcode the autoplay into the PHP scripts directly. I don’t know any PHP, but how hard can it be? :slight_smile:

Edit file /var/www/command/player_wrk.php and search for ‘WORKER MAIN LOOP’.
Add the following lines before the ‘// — WORKER MAIN LOOP — //’ line:

// Autoplay
sleep(5);
$cmd = ‘amixer cset numid=3 1’;
sysCmd($cmd);
$cmd = ‘mpc repeat on’;
sysCmd($cmd);
$cmd = ‘mpc random on’;
sysCmd($cmd);
$cmd = ‘mpc consume off’;
sysCmd($cmd);
$cmd = ‘mpc single off’;
sysCmd($cmd);
$cmd = ‘mpc play’;
sysCmd($cmd);

The amixer line tries to force 3.5mm jack audio output. Not sure this works. Omit it if you use your own DAC or HDMI.
Not sure the sleep(5) is necessary. This is actually not specific for NAS and should work with any source. It should play the playlist which was last active.

I would love to have this in the GUI, but I do not know how to hack that in.

Ah yes. Completely unrelated and just so I do not forget it: To get my TL-WN725N WLAN Dongle working with volumio 1.55 I had to download the firmware for it:
sudo wget github.com/lwfinger/rtl8188eu/r … 88eufw.bin -O /lib/firmware/rtlwifi/rtl8188eufw.bin

I am also having this problem with volumio 2. I think my next attempt will include a delay. Also will figure out why it cannot read any of my playlists from the command line (everything works fine from the browser).

hi sir, I am late, maybe this tutorial will help U cause I encountered the similar problem. http://www.videoconverterfactory.com/tips/mpc-to-mp3.html most of us are unfamiliar with MPC, and at present, there are few mainstream players, editing tools, mobile devices can be compatible with MPC, so for solving your problem, you can try to convert MPC to MP3.