Thank you for your donation!


Cloudsmith graciously provides open-source package management and distribution for our project.


Spotify Connect failures on Moode 4.4
#41
Hi guys,

New here  Smile Actually I'm not even a moodeaudio user - but I've been struggling with raspotify/librespot connection issues for ~2 years on 2 separate raspberry pi's and could never find the cause, let alone a workaround - but I came across something yesterday which seems (so far, fingers crossed) to have finally addressed it.

Symptoms experience (in past):
Connect from spotify, play music - music will randomly stop, mid-track. It could be after 10s, it could be after 10 tracks, it could be after an hour. But it WILL happen - generally within an hour. Sometimes the service is still running and I can still re-connect from Spotify and resume playing. Occasionally I'll need to send a quick service raspotify restart so the client can reconnect.

The logs, even verbose logging, display no indication of what is going on  Huh
I have more of these examples stored somewhere but here's what they generally look like:

Code:
Nov 20 10:27:42 officepi librespot[21836]: TRACE:librespot_audio::fetch: chunk 100 / 103 complete
Nov 20 10:27:42 officepi librespot[21836]: TRACE:librespot_audio::fetch: requesting chunk 101
Nov 20 10:27:43 officepi librespot[21836]: TRACE:librespot_audio::fetch: chunk 101 / 103 complete
Nov 20 10:27:43 officepi librespot[21836]: TRACE:librespot_audio::fetch: requesting chunk 102
Nov 20 10:27:43 officepi librespot[21836]: TRACE:librespot_audio::fetch: chunk 102 / 103 complete
Nov 20 10:27:43 officepi librespot[21836]: DEBUG:librespot_audio::fetch: File 96e6fe448652629359c13496af3121320d846eaa complete
[Crash happens here - the above is completely normal and happens for every track - I then restart the service]
Nov 20 10:28:01 officepi systemd[1]: Stopping Raspotify...
Nov 20 10:28:01 officepi systemd[1]: Stopped Raspotify.
Nov 20 10:28:01 officepi systemd[1]: Starting Raspotify...


Setup:
One is running OSMC and connected to USB speakers (I've had it ~1 year), the other is running Raspbian and connected to a TV using HDMI (~2 years). Both experience the same issue.

The workaround:
I came across an obscure post somewhere (which I've lost - I came across this looking for the original) which suggested running librespot manually in a terminal (rather than as a service). I decided to do so just to observe any additional errors that might not be getting logged... But so far my stream held steady the entire afternoon and I haven't experienced the issue.

So what I'm suggesting is disable the service and run librespot in a screen session instead. It's worth a shot.

I have the following simple script (remember to chmod +x it) to launch librespot:

Code:
pi@officepi:~ $ cat manlibrespot.sh
#!/bin/bash

/usr/bin/librespot --name stablepi --bitrate 320 --initial-volume 15 --enable-volume-normalisation --linear-volume --disable-audio-cache --verbose
#OPTIONAL ARGS:--backend alsa --device plughw:0 --onevent /var/local/www/commandw/spotevent.sh --username [USERNAME] --password [PASSWORD]

If you want to automatically start a screen session and run a script at boot I would suggest adding the following to the bottom of /etc/rc.local:

Code:
su pi -c '/usr/bin/screen -dmS manlibrespot /home/pi/manlibrespot.sh'
PS: it's possible the "d" daemon mode in that line might be an issue; still untested (I use that in other service that stop crash).
Reply
#42
Update:
2 days later, no drop-outs. That's me converted.

NOTE: This does NOT fix librespot crashing when there is a network interruption; however THAT crash has log entries and can be watched/restarted (I'll build that into the script later).

Here's the script I'm using to start/restart/stop librespot:

Code:
#!/bin/bash

launch_librespot () {
 screen -dmS librespot `which librespot` \
 --name osmc \
 --bitrate 320 \
 --initial-volume 50 \
 --enable-volume-normalisation \
 --disable-audio-cache \
 --verbose \
 --username XXXXXXXXXXX \
 --password XXXXXXXXXXX \
 --backend alsa
 #--device plughw:0 \
 #--onevent /var/local/www/commandw/spotevent.sh
 echo "librespot started"
}

if [[ "$1" == "start" ]]; then

 if [[ -z `screen -ls | grep librespot` ]]; then
   launch_librespot
 else
   echo "librespot is already running"
 fi
 exit 1

elif [[ "$1" == "restart" ]]; then

 if [[ -z `screen -ls | grep librespot` ]]; then
   echo "librespot not running"
 else
   echo "restarting librespot"
   kill -9 `screen -ls librespot | grep librespot | cut -d "." -f 1`
   screen -wipe | 1>/dev/null
 fi

 launch_librespot
 exit 1

elif [[ "$1" == "stop" ]]; then
 if [[ -z `screen -ls | grep librespot` ]]; then
   echo "librespot not running"
 else
   echo "stopping librespot"
   kill -9 `screen -ls librespot | grep librespot | cut -d "." -f 1`
   screen -wipe | 1>/dev/null
 fi
 exit 1

else
 echo "function: ./librespot [start|restart|stop]"
fi
Reply


Forum Jump: