Shairport and MPD won't get along

Hello,

I’m loving Volumio so far.

There is one thing though I’m trying to implement that I could with my previous raspberry home brew mpd/shairport player but can’t on Volumio. If I’m currently playing something using mpd, I’d like the mpd song to stop once an airplayed song tries to play. Right now, if I were to try this on Volumio, shairport poop sout and just stops working.

On my old install, I was able to get mpd to stop when airplay starts by editing: /etc/init.d/shairport. I added this extra bit: --play_prog=“mpc stop”, and it would work pretty nicely. Volumio is using a newer version of shairport, so it’s a little different. I’ve edited the /etc/init.d/shairport file and made a similar change: /usr/local/bin/shairport -d -a “$NAME” -B “mpc stop”. " It sort of works but only on the first try. The second attempt causes shairport to poop out again.

Any help would be greatly appreciated!

Would support that! However there are two more basic errors regarding shairplay:

  1. shairplay can not be restarted via command line:

root@volumio:~# service shairport stop
Terminated

but the shairplay process survives. It can not be killed via killall shairplay as done in /etc/init.d/shairplay, but must be killed via killall -9 shairplay

  1. When AirPlay is activated while mpd is playing, you get the following behavior (can be observed by starting shairplay service in terminal):

root@volumio:~# service shairport start
Listening for connections.
3515
Established under name …

so far so good - two processes were created: shairplay and the corresponding avahi-publish-service

Now try to use AirPlay while mpd is playing and you get the following stdout:

[i]ALSA lib pcm_dmix.c:1018:(snd_pcm_dmix_open) unable to open slave
FATAL: Alsa initialization failed: unable to open pcm device: Device or resource busy

Shutting down…
Got SIGTERM, quitting.[/i]

This has just killed the avahi-publish-service, but the shairplay process is still alive.

Yes, this is a issue that needs to be addressed, mind that the shairport version included in Volumio is quite outdated… .The reccomendation in the first post is truly interesting… I’ll digg into that… Thanks for the help ! :wink:

I just found a solution that has finally worked for me. The problem is mpd still uses the alsa device when you try to play something through shairport/airplay. When mpd stops, it no longer uses the alsa device and should be free for shairport to start playing.

Originally I had something like this in my /etc/init.d/shairport file which technically should work.

/usr/local/bin/shairport -d -a "Volumio" -B "mpc stop" 

“-B” sends a start command of “mpc stop” before trying to airplay something. For me, this worked the first time I tried after rebooting, but every time after it gave me the error above on my original post and shairport died.

Just now I looked at the shairport help and saw an option I never noticed before, “-w”. It waits for the shell command to complete before trying to play, so now shairport actually waits till mpd completely stops and releases the alsa device before airplaying. /usr/local/bin/shairport -d -a "Volumio" -w -B "mpc stop"
Wow, that was easy. I can now go back and forth between airplay and mpd without shairplay dying. One other thing, I do get this strange error “WARNING: exec of external start command failed”. It’s strange because the external start command did NOT fail.

Thank u for solving this problem, this realy is great news for me!!! Normaly when i have a party with friends i have to reboot 5-6 times a night because somebody is pushing the airplay while mpd still is playing:-)

So all we have to do is edit the shairport file ? Could you give us step by step instructions for linux newbies like me - thanks :slight_smile:

Shakey, I’m with you. Prior to volumio, I was using the perl version of shairport which seemed to work as expected when you set the start command to send “mpc stop”. But one weird thing I remember (could be dreaming it), if someone was already airplaying something, you couldn’t interrupt it by airplaying your own thing. You’d have to wait till the other person stopped their airplay before doing your own. This is not how normal apple airplay works. Airplay plays whatever is sent last. The C version behaves like apple’s, which in a party situation could be better, or I guess that’s arguable.

Icai, yes, that’s exactly it. You just need to edit that file. Here is the step by step:

  1. SSH into volumio. ssh volumio@volumio.local pw is volumio
  2. Edit your /etc/init.d/shairport daemon script. sudo nano /etc/init.d/shairport
  3. On the row that has: /usr/local/bin/shairport -d -a "$NAME" Switch it to: /usr/local/bin/shairport -d -a "$NAME" -w -B "mpc stop"
  4. Ctrl-X to exit. “Y” to save changes. Then Enter to save as current filename.
  5. Reboot sudo reboot Or you can just restart the shairport daemon. I’d just reboot though because why not? sudo /etc/init.d/shairport stop Then sudo /etc/init.d/shairport start There is no “restart” option with this daemon script.

What version of Shairport are you referring to?

I tried this but when I tried the “start” command it dumped the Shairport command-line and said the -w switch was invalid.

I’m running volumio 1.1 beta.

Ahh, that could be why I never noticed the -w option before. I installed the current version of shairport, master branch of v1.0.

One additional benefit of the current version of shairport is it now works with airfoil.

Could you give us the instructions how to install the new version?
Thanks :smiley:

I would also appreciate instructions on updating.

The instruction to update Shairport (by Dakku) is here:
tutorial-update-shairport-the-airplay-daemon-latest-t654.html

Thanks! With this update, the new Ios versions are able to stream to volumio.
Interestingly, the volume/quaility of Itunes radio relative to third party apps like iheartradio seems to be poor. Not sure if its my head acting up!! :confused:

tutorial-update-shairport-the-airplay-daemon-latest-t654.html