Squeezelite and shairport together on "blocking" DAC

Max2Play Home 2016 (en) Forums Max2Play on Raspberry PI Squeezelite and shairport together on "blocking" DAC

This topic contains 9 replies, has 4 voices, and was last updated by  Pastinakel premium 1 year ago.

Viewing 10 posts - 1 through 10 (of 10 total)
  • 21. October 2015 at 10:55 #16457


    After using Squeezelite and some form airplay emulation in different setups, I decied a couple of days ago to try out Max2Play. Love it.
    But: I cannot use Squeezelite and Shairport together on the Hifiberry Amp on my Pi B. As long as the Squeezelite client is in “on” power state, it blocks access to the soundcard for Shairport. Bummer.
    Shairtunes would be a pain to install on Synology so I came up with this:

    My solution:
    Use the telnet interface of Logitech Media Server (LMS) to switch of the client (not shut it down!!) as soon as the playback of Shairport starts. Shairport has special command line switch to achieve this ( -B, –on-start=PROGRAM -E, –on-stop=PROGRAM). As soon as the airplay stops, the squeezelite client is powered back on and the last playing state is restored.

    This script does the magic (relies on the netcat or nc command). Saved as /home/pi/script/sbc_switch.sh

    ### Squeezebox switch
    LMSIP="lms.home"                # LMS IP Address or hostname
    LMSPort=9090                    # LMS Port
    SBC_MAC='00:0f:13:29:14:22'     # Squeezebox Client MAC Address
    ### INIT
    shopt -s nocasematch
    echo "$1"
    if [ "$1" == "resume" ] ; then
      ### Resume
      SBC_PW=$(printf "${SBC_MAC} power 1\nexit\n" | nc $LMSIP $LMSPort 2>/dev/null | cut "-d " -f 3)
      SBC_LM=$(printf "${SBC_MAC} playerpref lastmode ?\nexit\n" | nc $LMSIP $LMSPort 2>/dev/null | cut "-d " -f 4)
      if [ "${SBC_LM}" == "play" ] ; then
        SBC_MO=$(printf "${SBC_MAC} mode play\nexit\n" | nc $LMSIP $LMSPort 2>/dev/null | cut "-d " -f 3)
      ### Shutup
      SBC_MO=$(printf "${SBC_MAC} mode ?\nexit\n" | nc $LMSIP $LMSPort 2>/dev/null | cut "-d " -f 3)
      SBC_LM=$(printf "${SBC_MAC} playerpref lastmode ${SBC_MO}\nexit\n" | nc $LMSIP $LMSPort 2>/dev/null | cut "-d " -f 4)
      SBC_PW=$(printf "${SBC_MAC} power 0\nexit\n" | nc $LMSIP $LMSPort 2>/dev/null | cut "-d " -f 3)

    I altered the shairport startup script to add the command line switches:

    SHAIRPORT_OPTIONS="--on-start /home/pi/script/sbc_switch.sh shutup --on-stop /home/pi/script/sbc_switch.sh resume"

    Then altered startup line:
    /sbin/start-stop-daemon --start -b -m -p /opt/shairport/log/shairport.pid --chuid $USER --startas /bin/bash -- -c "exec /opt/shairport/shairport --name \"$NAME\" -o alsa -- $SHAIRPORT_PARAMETER > /tmp$
    /sbin/start-stop-daemon --start -b -m -p /opt/shairport/log/shairport.pid --chuid $USER --startas /bin/bash -- -c "exec /opt/shairport/shairport --name \"$NAME\" -o alsa $SHAIRPORT_OPTIONS -- $SHAIRPORT_PARAMETER > /tmp$

    There is a little trick involved that stores the last playing state of the client in a custom variable “lastmode” on the LMS itself. As soon as Shairports powers the squeezelite client back on, the last playing state is restored by reading that variable.

    Thought I’d share this with you.

    • This topic was modified 1 year, 1 month ago by  Pastinakel.
    • This topic was modified 1 year, 1 month ago by  Pastinakel.
    • This topic was modified 1 year, 1 month ago by  Pastinakel.
    22. October 2015 at 18:04 #16525

    Hi Pastinakel,

    thank you very much for sharing this with us. Definitely cool thing we will consider in future updates as an optional feature.
    Running an LMS version 7.8 and above, the Squeezebox plugin “Shairtunes 2” emulates Airplay and, therefore, is a good combination. Your solution, consequently, makes sense for owners of Squeezeboxes running older versions of LMS (e.g. 7.7).

    Best regards

    Maximilian from Max2Play

    24. October 2015 at 23:19 #16550

    Thanks Maximillian.

    I’m stuck with a Synology NAS and I could achieve a working installation of the Shairtunes 2 plugin. There are other solutions to be found on the net that involve shutting down the squeezelite process completely. But I think the above is more elegant.

    I tried installing LMS + Shaiport 2 plugin on the Pi2 I ordered in the Max2Play shop recently. It works but there is a big lag when using the plugin. I like the Shairport process on the Pi itself because of the minimal lag.

    Best regards,


    26. October 2015 at 16:10 #16555

    Hi Nico,

    I just added a modified version of your script to the latest Max2Play Beta (will be part of the next release). You can now specify the LMS IP in the Advanced settings of Shairport. This will trigger the usage of the Start/Stop script. After restarting Shairport it will make use of this feature.

    We really appreciate your help and thanks again for sharing this!

    All the best,

    11. November 2015 at 23:50 #16864

    Hi Stefan,

    The Raspi 2 / Hifiberry Digi / 7 ” screen combo I just bought in the M2P shop works great with this option in the latest release. Thanks for adding this option to the package.


    30. November 2015 at 22:42 #17069

    Hi, I have a somewhat easier setup, but it still does not work at all.

    It is a Pi 1 B+ model with a HifiBerry compatible I2S soundcard.
    I downloaded and installed the M2P HifiBerry image to an 8GB card and did the initial setup in M2P:
    1) enter email adress
    2) install M2P update
    3) set up soundcard
    4) mounted network drive (all ethernet)
    5) added libs to LMS
    6) installed/activated Shairtunes2 plugin

    Squeezeplug is running fine, radio stations work fine and the LMS settings/plugin page shows the Shairtunes2 plugin as active.

    From reading existing documentation it is not clear to me whether this setup as such would already be good enough to enable airplay. Because when looking into the airplay menu on the iPhone (same network of course), no airplay capable device is detected. (I know that the hardware can do this, with the RuneAudio setup airplay to the same hardware config was not an issue).

    So I tried to launch the Shairport process from the Audioplayer tab. It claims to launch and then successfully having started a proc ID. But when navigating away and back to the audioplayer tab it is either not running (or showing a higher process ID number, in case auto start is activated). In its settings I have tried various soundcard options and also the automatic audio switch (filling in the M2P’s IP address).

    None of these actions would make airplay available in the network.

    I guess both processes (Shairtunes and Shairport) are needed? If so, I assume the Shairport process should remain as is instead of crashing and starting over all the time, which is probably happening now. Any hints how to investigate and fix this?

    Interestingly, I had the same trouble with a different Raspi using a non-hifiberry-M2P image with an USB-Soundcard, some month ago, but gave up fixing it. But now that both machines are not working, this is too bad…

    Any help is greatly appreciated!
    Best, Andreas.

    30. November 2015 at 23:06 #17071

    On the M2P Audioplayer tab it says:

    “To use Airplay you may choose the Shairport player OR the plugin Shairtunes (install on Squeezebox Server tab), that enables all Squeezeplayers (such as Squeezelite) to act as an Airplay device. This is useful if a soundcard supports only one connected player.”

    Does this mean EITHER OR? That could explain why Shairport crashes. But if so, I don’t get the idea of the switch described above.

    Please, help clarifying this. Thank you!

    30. November 2015 at 23:37 #17073

    Hi waterdrinkingman,

    There are two different issues here at play but they have some connection. Let me explain.

    1. Airplay. Either choose Shairtunes 2 plugin on the LMS server OR use Shairport on the Pi itself. Don’t use both.

    2. Two different processes on the same soundcard (Squeezelite and Shairport). Only an issue if you have a “blocking” soundcard.

    Pick your scenario:

    A. Use Shairtunes 2 plugin in LMS. No need to start Shairport on the Pi (don’t do that!!). If this works, then you’re done. Issue 2 is no problem because the playback on the Pi is handled by Squeezelite.

    B. Use Shairport on the Pi. Then disable Shairtunes 2 plugin in LMS or the will collide and confuse your iPhone when looking for Airplay targets. If you use this option you have to decide how to unblock the soundcard at the moment you want to Airplay. Either do it manuallu or use the method described above.

    Hope this helps.

    I tried both but settled for B because of lower lag when watching video with sound over Airplay.

    1. December 2015 at 1:10 #17075

    So I stopped the LMS, squeezelite and also shairport. removed the autostart. rebooted. then only started shairport. should be no conflict then, correct? iPhone won’t find any airplay device.

    again, stopped all services. Only started LMS, made sure that shairtunes2 plugin is active. no airplay device. :-/

    1. December 2015 at 11:47 #17078

    Well, at least we have clear now that it has nothing to do with the topic in this thread. But that does not help you any further. ­čśë

    Time to do some log digging .. I think …

Viewing 10 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic.

Register here