Page 1 of 2

MPD starts playing after boot

PostPosted: 22 Mar 2014, 17:40
by Midnight
Hi,

it seems MPD automatically starts playing after boot, even if it was paused/stopped before.

Note: I'm switching it off without shutdown command.

Re: MPD starts playing after boot

PostPosted: 22 Mar 2014, 19:00
by dopus
Same here.Mabye it is fixed in the next release.

Re: MPD starts playing after boot

PostPosted: 23 Mar 2014, 13:59
by tc-fi
same here----starts playing after boot!

Re: MPD starts playing after boot

PostPosted: 23 Mar 2014, 14:13
by Midnight
It ruins my last.fm profile because it submits tracks everytime I turn on my stereo (which also turns on the rest of my multimedia stuff) :evil: ;)

Re: MPD starts playing after boot

PostPosted: 17 Apr 2014, 22:06
by junaling
This happens to me when I do a shutdown through ssh while still playing, however if I stop/pause the current song before issuing the shutdown it does not.

Re: MPD starts playing after boot

PostPosted: 05 Jun 2014, 15:41
by Midnight
junaling wrote:This happens to me when I do a shutdown through ssh while still playing, however if I stop/pause the current song before issuing the shutdown it does not.

This is the intended behaviour and therefore there is a MPD state file in the config:
state_file "/var/lib/mpd/mpdstate"


Maybe there should be an option to disable the state file completely.

Re: MPD starts playing after boot

PostPosted: 12 Jul 2014, 09:01
by LosHermanos
Hi there,

Mine doesn't start playing at all at boot, whatever I do. I am playing with 0.3 (0.2 doesn't work at all on my Pi).
I also noted that the state file isn't changed anytime. I thought playing with the state file might get me autostart, but I can't get it to work.

Re: MPD starts playing after boot

PostPosted: 16 Jul 2014, 17:24
by Midnight
Midnight wrote:Maybe there should be an option to disable the state file completely.

BTW: after disabling the state file mpd also loses it's playlist after restart, so this is not an option.

Re: MPD starts playing after boot

PostPosted: 18 Jan 2015, 00:36
by waves
Yes this is a bad bug. Imagine that a user leaves RuneAudio on with high volume but in pause mode and there is e.g. a brief power outage that involuntarily reboots the pi during the night. Both the user and the neighbors would get a not so pleasant awakening at 3 a.m. :)

I work around the bug with a script that runs at boot (set up with systemd) and repeatedly executes the "mpc stop" command for around 30 seconds, since the RA/mpd seem to resume play with a little delay. That works. But I hope the bug will be fixed properly.

Re: MPD starts playing after boot

PostPosted: 23 Jul 2015, 02:43
by daymz
OK, I`ve spent the entire day on this because I just hate the auto-play on boot behavior. I do want the state saved to keep the existing playlist, but in my case, resuming play on boot makes no sense at all (ex: power outage at night - boom, sound system starts blasting music I was listening to some other day)

The fix is in several parts:
1) make sure that the mpdstate file is on "pause" at startup
2) remove a play command in orion_optimize.sh

The following tutorial was done on RuneAudio 0.3 for Raspberry PI.

Part 1 : Change mpdstate before mpd starts

When mpd quits, it saves it states to the state file (/var/lib/mpd/mpdstate). If your device rebooted while it was playing, we will want to have it chagned to pause in order ot avoid mpd restart play.

Create a new script and save it somewhere (example here: /home/user/mpd_state_pause). The script will modify the mpdstate file so that the mpd state is always "paused"

Code: Select all
#!/bin/sh

# Modify MPD's state file to ensure current state is "pause"
sed -i 's/^\(state: \).*/\1pause/' /var/lib/mpd/mpdstate


Now, let's run that script before starting mpd. The best way is to use systemctl's ExecStartPre directive. Modify /usr/lib/systemd/system/mpd.service to add the ExecStartPre line below: (don't forget to change the path of the script to the location you chose earlier)

Code: Select all
[Unit]
Description=Music Player Daemon
After=network.target sound.target

[Service]
ExecStartPre=/home/user/mpd_state_pause
ExecStart=/usr/bin/mpd --no-daemon

[Install]
WantedBy=multi-user.target


Part 2 : Fix the orion_optimize.sh script

Even though I did Part 1, I could see in the UI that MPD was being restarted, and oh no, play resumed. It took me a freakin' while, but I eventually found out that /var/www/command/rune_SY_wrk was calling /var/www/command/orion_optimize.sh, and at line 159, that script was calling "mpc play".

Comment out "mpc play" at line 159.

Code: Select all
sndusb_profile() {
local "${@}"
mpc pause > /dev/null 2>&1
sleep 0.3
modprobe -r snd-usb-audio
echo "options snd-usb-audio nrpacks=${nrpacks}" > /etc/modprobe.d/modprobe.conf
sleep 0.2
modprobe snd-usb-audio
sleep 0.5
#mpc play > /dev/null 2>&1
#mpc pause > /dev/null 2>&1
#######mpc play > /dev/null 2>&1
}


Part 3 : Test your setup

Go to the RuneAudio web UI, put a couple tunes/web radios in the queue, hit Play. Now reboot the device.

Once rebooted, the queue should still contain all your files, but play will not resume. It will be paused.

Enjoy!