[HowTo] Setup a spotify-connect-web-server on a Raspberry Pi with OSMC

Forgive me if the example of your modified script explains how to install the spotify connect service, but could you go into a little further explanation on how you did this on the rpi3? I believe im exactly at this step and ive been hung up on it for a few days now with no luck. Any advice is greatly appreciated. Thank you.

Ok so you should have the script in the osmc folder:
/home/osmc/spotify-connect-web.sh

Now edit the script, you have to replace “$DIR” with “spotify-connect-web.sh” but only in the IF statement"
sudo nano /home/osmc/spotify-connect-web.sh
Now find “mkdir -p $DIR” and change it to “mkdir -p spotify-connect-web.sh”
Do the same for “cd $DIR” change it to “cd spotify-connect-web.sh”

Done! Now save your changes with CTRL+O and exit the editor with CTRL+X. Now just run the sh script just like you did before with install. It will download again and you will notice after download it will “hang” for a few moments (it is extracting the files to the correct location now).

Hello!
First of all, amazing How-To. It worked like a charm.

I’ve got a Pi 2 Model B with newest OSMC (June 2016).
The Device is connected to my AVR (Pioneer) via HDMI (so it’s HDMI-audio passthrough).

I’ve got the following problem, i hope that someone can help me out with this.

  1. Spotify Connect is autostarted as a service
  2. Videos in Kodi play without a problem.

But under the following circumstances there’s a problem with playing video files:

  1. Booting the Pi, Kodi starts
  2. I play music via Spotiy Connect - everything is fine
  3. I stop playing music via Spotify Connect
  4. Then, when i play a video file (.mkv), i’ve got no sound and a black screen.

So the problem is present when i used spotify connect once.
When i reboot the Pi the problem is gone, until i use spotify connect.

Here’s the logfile, you can see the error regarding the sound-device:
20:21:28 106.991058 T:1956725680 DEBUG: CGUIInfoManager::SetCurrentMovie(nfs://192.168.2.10/NAS-WDRed1/Movies/Movie.mkv)
20:21:28 106.992645 T:1555035120 DEBUG: COMXCoreComponent::Initialize OMX.broadcom.audio_render input port 100 output port 100 m_handle 0x5e124990
20:21:28 106.995308 T:1555035120 DEBUG: COMXAudio::PortSettingsChanged - bits:0 mode:0 channels:0 srate:0 passthrough
20:21:28 106.997055 T:1884287984 ERROR: COMXCoreComponent::DecoderEventHandler OMX.broadcom.audio_render - OMX_ErrorInsufficientResources, insufficient resources
20:21:28 106.997307 T:1555035120 ERROR: COMXAudio::PortSettingsChanged - m_omx_tunnel_decoder.Establish omx_err(0x80001000)
20:21:28 106.997536 T:1555035120 ERROR: COMXAudio::AddPackets - error PortSettingsChanged omx_err(0x00000000)
20:21:28 106.997650 T:1555035120 INFO: COMXPlayerAudio - Switching to normal playback
20:21:28 107.002357 T:1577055216 DEBUG: CDVDPlayer::HandleMessages - player started 1
20:21:28 107.002548 T:1577055216 DEBUG: CDVDPlayer::HandleMessages player started RESET
20:21:28 107.002617 T:1577055216 NOTICE: OMXClock using audio as reference
20:21:28 107.003006 T:1577055216 DEBUG: OMXClock::OMXReset audio / video : 1 / 1 wait mask 0->3 state : 2->1
20:21:28 107.003105 T:1577055216 DEBUG: CDVDPlayer::HandleMessages player started 1 (s:1000 a:1 v:1)
20:21:28 107.003189 T:1577055216 DEBUG: CDVDPlayer::SetCaching - caching state 0

What i have done so far:

  1. I’ve played with the gpu_mem_1024 variable in the config.txt, default is 256, i also tried 512 and 768. This does not help
  2. Enabled enhanced Debug logging but no hint what is exactly the problem here
  3. Hardware accelleration for OMX Player is enabled.

It seems like there is a problem with using the same audio device for spotify connect and for kodi-audio.
The problem is present when playing .mkv’s. Disconcertingly, my iPhone .mp4 Files played well.

I hope that someone has an idea :slight_smile:

Cheers
Dom

No clue, I have the same setup. Also set Kodi to passthrough. Did you do step 20a?
I can play a video after I stop Spotify playback in the app on my laptop or mobile. I do have sound.

But sometimes when I play a video (usually after I haven’t used Kodi a while) I have no sound, but I can do everything (Kodi works, video plays back) so I just reboot. Never thought it could be related to Spotify because it never happened right after I played Spotify. Also I never bothered to check the log… Will do that next time I have no sound.

I will check that 20a setting.
And yeah, its pretty weired. But it’s definitive related to the spotify connect playback because when i’m not playing music via spotify, the video files just play fine.
And then, after using spotify connect once, the video files don’t play …

hdmi_force_hotplug did not help.

:frowning:

Hello Zatarra,

Yes I finally succeeded using Spotify Connect and OSMC on the same Rbpi1.
All right it isn’t really same time but I found a way so I can use one after another in an easy way.

Hope I’ll be clear enough so the time I spent on this doesn’t go to waste.
Please bear with me here because I just opened a shell book and tried a way of doing what I wanted it is probably not the best way to do It but it does Work.

The goal of this script is find out if spotify connect OR OSMC (mediacenter service) is running if one of them is running it stops it and start the other one.

Then I used “Hot Button SSH Command Widget” available for free on play store to make a shortcut on my phone to this script.

Here it is :slight_smile:

#!/bin/bash

# check service status and store results in variable
systemctl status scsk.service ; spotifyconnect=$?

# check service status and store results in variable
systemctl status mediacenter ; mediacenter=$?

# if one of the variable is smaller than the other ex: 0<1 (depending on exit code)
# it means the one that has 0 for value is running 
# So stop it and run the other one and the other way around depending on results

if [ $mediacenter -lt $spotifyconnect ]
then
systemctl stop mediacenter
sleep 2
systemctl start scsk.service
elif [ $mediacenter -gt $spotifyconnect ]
then
systemctl stop scsk.service
sleep 2
systemctl start mediacenter
fi

Then I used the app mentionned above to create an ssh shortcut to the script.

And well it just works.

But because there is always one :slight_smile:
Something I haven’t resolved yet.
After using the script if I try connecting from computer to OSMC by ssh I get :

PTY allocation request failed on channel 0

Workaround is :

ssh -T user@host 

So it avoids TTY request.

Cheers

For me a shortcut to start and stop spotify connect service is sufficient. No need to restart kodi. I just stop the spotify service and have sound again if I play a video in kodi.

Interesting, maybe I have to wait a little longer between changes ?
If I just stop and try watching something on kodi sounds default to hdmi.
Through graphic interface I the nhave to select HDMI ( seems like nothing is selected after I used spotify connect ) and then re-select HifiBerry and then it works again !?!

That’s why I’m using above script.

Do we have the same setup ?

OSMC Rbp1 + HifiBerry DAC+

Oh, no I have vero2 and use hdmi out to av receiver.

Here is a more to-the-point how to, from a linux computer (updated for the latest version of the chroot and to fix a small mistake):

Connect and download the script:
ssh osmc@osmc.lan
mkdir extras && cd extras
curl -OL https://github.com/Fornoth/spotify-connect-web/releases/download/0.0.3-alpha/spotify-connect-web.sh
chmod u+x spotify-connect-web.sh
As I’d rather have the chroot live in ~/extras, edit spotify-connect-web.sh to change its DIR variable:
nano spotify-connect-web.sh, find DIR= and change from DIR=~/spotify-connect-web-chrootto DIR=~/extras/spotify-connect-web-chroot. ctrl+x to close, Y to confirm changes.
then actually install it:
./spotify-connect-web.sh install

From your computer, download your binary spotify app key from the spotify website, then send it over using scp:
scp ~/Downloads/spotify_appkey.key osmc@capybara.lan:/home/osmc/

And back on the osmc box, move it to where it should go:
sudo mv ~/spotify_appkey.key ~/extras/spotify-connect-web-chroot/usr/src/app

Test it out:
./spotify-connect-web.sh --username $YOURSPOTIFYUSERNAME --password $YOURSPOTIFYPASSWORD --bitrate 320 --name $NAME_OF_YOUR_OSMC_COMPUTER_AS_WILL_APPEAR_IN_THE_SPOTIFY_APPS
ctrl+C to stop it

Then sudo nano /etc/systemd/system/spotify-connect-web.service
copy paste the systemd unit script graciously provided by @zatarra (slightly modified to suit my favoured path):

[Unit]
Description=Spotify Connect
After=network-online.target
[Service]
Type=idle
User=osmc
ExecStartPre=/bin/sleep 25
ExecStart=/home/osmc/extras/spotify-connect-web.sh --username $YOURUSERNAME --password $YOURPASSWORD --bitrate 320 --name $NAME_OF_YOUR_OSMC_COMPUTER_AS_WILL_APPEAR_IN_THE_SPOTIFY_APPS
Restart=always
RestartSec=10
StartLimitInterval=30
StartLimitBurst=20
[Install]
WantedBy=multi-user.target

ctrl+X to exit, Y (yes) to confirm and save
make the systemd unit executable:
sudo chmod a+u /etc/systemd/system/spotify-connect-web.service
sudo systemctl daemon-reload
sudo systemctl enable spotify-connect-web.service
sudo systemctl start spotify-connect-web.service

This should be a bit faster for those used to the linux commandline :slight_smile:

1 Like

Two more things I discovered.

This is my setup: the raspberry pi 2 is connected to the TV over HDMI but also to an analogue amp over, you guessed it, analogue output, to be able to get louder, better sound (with the caveat of some noise and distorsion at low volume).

When playing music with Spotify through spotify-connect-web, the sound was always coming out of the TV and not the analogue amp, no matter what output I chose when starting spotify-connect-web with --device ALSADEVICENAME. Even --device hw:CARD=ALSA,DEV=0 (bcm2835 ALSA, bcm2835 ALSA, Direct hardware device without any conversions) was outputting to HDMI.

It turns out Raspberri Pis will automatically output sound to HDMI if that’s detected.
To change that, run amixer -c 0 cset numid=3 1 to force the sound of the default alsa device to go through analogue, even when a receiver that can play sound is detected over HDMI. (amixer -c 0 cset numid=3 0 will set it back to the original setting, letting the raspberry pi choose automatically).

Furthermore, if like me you don’t like having your login and password show up in the spotify-connect-web arguments and in the systemd unit (and thus visible to anyone who can ssh into your OSMC box… who changes the password on their media centre honestly?) you might like to know that you can login with your credentials on the command line once and then leave them out.
Spotify-connect-web will store them in /usr/src/app/credentials.json and use them every time it starts. And if need be, you can always enter them on the webpage at osmc.lan:4000. You can probable even never enter them on the command line and just through the web interface actually.

At step 10 I get this error message on Vero 2:

SpInit: 0
Traceback (most recent call last):
File “main.py”, line 27, in
connect_app = Connect(web_error_callback)
File “/usr/src/app/connect.py”, line 75, in init
lib.SpPlaybackUpdateVolume(mixer_volume)
OverflowError: can’t convert negative number to unsigned

Any recommendations on a fix?

See this post:

This configuration worked for me

Rpi Model 2 b+ with raspbian-Jessie:

[Unit]
Description=Spotify Connect
After=network-online.target
[Service]
Type=idle
User=pi
ExecStartPre=/bin/sleep 25
ExecStart=/home/pi/spotify-connect-web.sh --username [username/email] --password [pass] --bitrate 320 --name [name]
Restart=always
RestartSec=10
StartLimitInterval=30
StartLimitBurst=20
[Install]
WantedBy=multi-user.target

For rpi 3 with raspbian-Jessie

[Unit]
Description=Spotify Connect
After=network-online.target
[Service]
Type=idle
User=root
ExecStartPre=/bin/sleep 25
ExecStart=/home/pi/spotify-connect-web.sh --username [username/email] --password [pass] --bitrate 320 --name [name]
Restart=always
RestartSec=10
StartLimitInterval=30
StartLimitBurst=20
[Install]
WantedBy=multi-user.target

Regards

Is there a reason you’d run the service as root? It’s not recommended to run stuff as root, unless you really know what you’re doing.

In other news, Fornoth updated the chroot of spotify-connect-web basing it on the 0.0.3 release. I’ve updated my install instructions to match.

Hello there,
I’ve done all this but can’t get the spotify server to run
I get :

osmc@osmc:~$ ./spotify-connect-web.sh --username $myuser --password $mypass --bitrate 320 --name Raspi
SpInit: 2
/bin/bash: line 1: 16025 Segmentation fault      python main.py --username $myuser --password $mypass --bitrate 320 --name Raspi
osmc@osmc:~$ 

Any ideas why?

Edit : I’ve had difficulties finding the app key from the spotify website
I’ve added a App in Spotify Developer website and they gave me Client ID and Client Secret. I’ve made a file called spotify_appkey.key with only the Client ID in it, can someone show me their key file (blanking out the binary of course) just to see what that file should look like?

This is Awesome!! been looking for this 4 ever, thnx so much!

Is it possible that multiple user have access to the connect server?
I created a new skript with following content
sleep 30 avahi-publish-service TestConnect _spotify-connect._tcp 4000 VERSION=1.0 CPath=/login/_zeroconf
as described here.
After chmod I put the script to etc/rc.local.
It is actually working after restarting the app but I’m sure there is a nicer solution.

Furthermore are there any news or hints about using a soundcard like hifiberry or iqaudio?

I could solve the issue, that I couldn’t easily change between audio outputs of kodi and spotify connect. Simply change “keep audio device alive” to off.
Beside that adding playback_device hw:0 --mixer Analogue helped adding my IQAudio like soundcard.