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 17 replies, has 9 voices, and was last updated by  Mbydeen 8 months, 1 week ago.

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

    Hello,

    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

    #!/bin/bash
    
    ### 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)
      fi
    else
      ### 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)
    fi
    

    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$
    to
    /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, 12 months ago by  Pastinakel.
    • This topic was modified 1 year, 12 months ago by  Pastinakel.
    • This topic was modified 1 year, 12 months 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,

    Nico

    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,
    Stefan

    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.

    Nico

    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 …

    19. December 2016 at 13:42 #24990

    My problem : Squeezelite does apparently not stop when trying to use AirPlay.
    My setup: I’m running LMS 7.8.1 on a MacMini, max2play on a RPI2 with a Hifiberry DAC+ card – connected to my old amp using RCA.
    In the “Audioplayer tab” the status is :
    Status: Squeezelite is running with processID 4773
    Status: Shairport (Airplay) is running with processID 761
    I can start playback from the LMS interface (or my phone using iPeng), and the music plays.
    When I try to play some music on my iPhone and choose the max2play airplay device, no sound is comming out
    In the advanced setting’s for Shairport i tried both to add macmini and 192.168.1.4 in the field for “Shairport/Squeezelite automatic Audio-Switch”

    I can manually stop the Squeezelite using the button, and then AIrplay starts.
    Is there some problem with the script ? Shoul this not work out-of-the box

    19. December 2016 at 14:01 #24992

    What happens if you manually telnet to LMS server from max2play device and issue “power 0” command?

    19. December 2016 at 14:44 #24998

    Hi KimT,

    this works out of the box when the LMS is running on Max2Play. It might be because of a different network Port, that is used for the commands. Default for the CLI (command line interface on LMS) is 9090. You might check this in your LMS settings. Another point might be a Firewall issue with your MAC, that blocks incoming traffic on this port.

    19. December 2016 at 15:01 #24999

    My server is running om port 9000, and you are right the CLI is running on port 9090.
    I tried to use a “telnet 192.168.1.4 9090” from my macmini (not the pi).
    And then a power 0 command. The respone i got was : 00%3A04%3A20%3A28%3Ac5%3A26 power 0

    (just to se if the connection to the server was OK I also tried “player count ?” and the responce was correct “player count 4”)
    I also tried using the telnet from a MacBook to my MacMini. There is no firewall blocking.

    • This reply was modified 10 months ago by  KimT.
    • This reply was modified 10 months ago by  KimT.
    • This reply was modified 10 months ago by  KimT.
    19. December 2016 at 18:55 #25040

    Can the problem be that the power 0 is issued to the wrong player ? I have 3 Squeezebox Radio’s and the Pi connected to the LMS on the MacMini, and the mac address I’m getting back is from one of the radio’s – not the Pi

    In the first post – the original script the mac address is hardcoded. I can’t find a script on the Pi – so I can’t find out how the mac address is found.
    Maybe you should add a field to the advanced option tab where an mac address could be added – or just make sure that the mac address it is using is for the device where the setting GUI is running

    13. January 2017 at 16:58 #25876

    Hi Kim,
    You can find the MAC Address of each Max2Play device by checking the Debug Info of the WiFi/LAN menu in the web interface.

    12. February 2017 at 20:41 #26868

    Hi Kim,
    First sorry for my english cause it’s not my mother language. I’ve max2play v2.40 on a rpi3.
    I had the same problem with shairport. For the automatic switch between shairport and squeeze lite i typed the ip adress of my squeeze box server (on my synology nas) without any extension. 192.168.1.56 for example without :9000 or 9090 at the end and it worked. I checked that on my squeeze box server the command line was accessible via the 9090 port. Now everything is working fine for the automatic switch between squeezelite and shairport.
    Hope that it’ll help others.

    13. February 2017 at 15:56 #26896

    Dear arnaju,

    Thank you for your information.

    The Default port for the CLI (command line interface on LMS) is 9090. and the port for Squeezebox Server Web administration interface is 9000.

    Best Regards,
    Mohammad Mbydeen

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

You must be logged in to reply to this topic.

Register here