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

That worked! Thanks!

To be able to use 2 accounts:
I created (but not enabled) a secondary service file, calling it scs-z.service. In this file I specifically point to a different key file of the 2nd Spotify account. Now I can do sudo service stop scs.service and sudo service start scs-z.service to switch.

So in my secondary scs-z.service file I use:
ExecStart=/home/osmc/spotify-connect-web.sh --key /home/osmc/spotify-connect-web-chroot/usr/src/app/rud/spotify_appkey.key --username [user]--password [pw[ --bitrate 320 --name [name]

And by not doing systemctl enable scs-z.service, this will not start at boot (since that would conflict with scs.service).

I am sure it is very easy to write a script that would check which of the 2 services is running, stop the running service and start the other service, to easily switch between accounts…

BTW on the Spotify dev page it says:

Important! LibSpotify and CocoaLibSpotify are no longer under
active development on any platform and are considered deprecated. If you
are building applications for iOS or Android, please use the iOS SDK or Android SDK, and we will be providing a new library for other platforms later this year.

Hopefully this solution will work untill Spotify provides us with an even better solution…

Same here. The service will restart because of an 203/EXEC if I put the credentials into scs.sh

Once I put em back to the scs.service - as you suggested - it runs perfectly.

Not really sure what the problem could be. Permissions? Or maybe scs.sh isn’t finished loading while the service moves on?

@hux,

No idea. That’s far beyond my linux/script/whatever knowledge. For now I adjusted the howto to the former version (without scs.sh).

Apologies @zatarra - I’ve amended my post above with the details of the scs.sh file - the initial # wasn’t showing up properly, it’s required otherwise it won’t work properly…

Thanks guys, it works like a charm. Also with the amended script by @Pezzy.
Although, I still have my password showing up in the logs - I consider that a minor issue.

Also, don’t seem to be having any problems with video sound over HDMI, after having stopped spotify playback over HDMI.

Hi guys, it works very well with Rpi 1 B+ and HiFiBerry DAC+ by adding --mixer Analogue.

I still have an issue maybe I haven’t well pinpointed the issue BUT when I play files (music or video with OSMC ) then stop them and launch spotify connect I have an Alsamixer message.

here it is :

Traceback (most recent call last):
  File "main.py", line 9, in <module>
    from connect import Connect
  File "/usr/src/app/connect.py", line 8, in <module>
    from console_callbacks import audio_arg_parser, mixer, error_callback, connection_callbacks, debug_callbacks, playback_callbacks, playback_setup
  File "/usr/src/app/console_callbacks.py", line 21, in <module>
    card = args.device)
alsaaudio.ALSAAudioError: Device or resource busy

If I run sudo systemctl stop mediacenter then spotify connect works beautifully ?

So either Im wrong about medicenter interfering OR I need help scripting mediacenter stop before spotify and vice versa

Thank you guys.

EDIT2 : Got it working by following OP 1st post, so I created and launched spotify connect as a service and it does work.

EDIT3 : Alllright so If I start spotify service then osmc default to another audio output and I have change it to to hdmi then back to snd hifiberry to make it work through DAC+ again

Help would be greatly appreciated otherwise I’ll script start spotify connect

sudo systemctl stop mediacenter
sudo systemctl start scs.service

and the other way around when I want to use OSMC

But I’m sure you readers have a better way of doing this.

Thank you.

@Krotin,

You obviously got a lot further than me with my ‘digi+’. But it’s the same issue. Hifiberry says shared sound cards isn’t supported…

So, it’s logical that OSMC seeks another audio-output when the spotify service is using the hifiberry.
I’m going to give their suggestion with mmap a try when I have spare time. Change to pulseaudio had crossed my mind. Does anyone has experience with either mmap or pulseaudio?

Thank you for providing this information with the link.
So I guess I will have to script something to start and stop services by testing if the other one is running and find an app that makes SSH shortcut for Android.
I.ll be back with my findings and I.m Sur your readers will greatly improve it.Thank you zatarra

Hi. I’m able to run spotify connect but there seems to be a problem in the connection. It seems like spotify connect wont use all available bandwidth and the audio pauses every second then play again. I’ve tried 160kbps and 96kbps but the audio still stutters. Any ideas to why is this happening? Great tutorial btw. Thanks.

@ryangco11,

Sorry, can’t say my knowledge goes that far. No idea.
What device do you use? Could it be that it hasn’t enough cpu-power, maybe because you have other programs running?

Zatarra

It worked and I’m very happy! Tx, tx, tx!

Some corrections:
I have NOOBS installation, so I had to change step
9. Copy the Spotify-key to the right place, by typing:
sudo cp /boot/spotify_appkey.key spotify-connect-web-chroot/usr/src/app/

to sudo cp /media/boot/spotify_appkey.key spotify-connect-web-chroot/usr/src/app/

And do I need to install Spotify connect web server three times?
Maybe steps 8 and 13:
'8. Open Putty again, and repeat step 4
'13. Repeat step 4 (login with Putty)
should be “repeat step 3” (login with putty?)

I had difficulties to get Spotify Appkey but I finally managed to connect my Spotfy account to developer account…

And now it works, I can send Spotify from phone to device “Raspberry Pi”! Tx again!

Do we have something similar for TuneIn or vTuner Radio?

There is an official Kodi add-on for Tunein.

Install it, login via the configure option. Now you will see the stations you are following (add them via your phone)

@bJako,
LOL! You don’t need to install Spotify connect web three times. It should be “repeat step 3” :wink:
I changed it.

@Krotin,

Any luck with using Kodi and Spotify simultaneously?

1 Like

zilexa4d
There is an official Kodi add-on for Tunein.
Install it, login via the configure option. Now you will see the stations you are following (add them via your phone)

But I cannot control TuneIn from phone, I have to use Yatse Remote or Kodi+TV/monitor. That’s quite ok, but I like Spotify stile - one app in phone to control all players/devices.
I can cast TuneIn to my Chromecast Audio… but not to Raspberry :frowning:

…removed post

That is something Tunein has to build, like Spotify created Spotify Web.
You still need an app to remote control Kodi, might as well be Yatse. I believe you can actually see the tunein channels in Yatse, so your TV can stay off (audio going to your reciever).

I can use Yatse and see TuneIn channels (and control most of addons) without TV.

But using ChromeCast (Audio) I just install CromeCast to iOS/Android and it will add “Cast to Chromecast” button to some apps (like Spotify and TuneIn) - then I use TuneIn app to choose channels and cast to Cromecast.

But then you probably have to switch inputs on the device you plug the Chromecast in. Extra step :stuck_out_tongue:

I had the chance to install OSMC on a new RPi3 and now I can definitely confirm:

That command really only downloads the 170MB file. It does not install it. And the file it downloaded is nowhere to be found, even though I saw the download progress.

I tried it on a cleanly installed RPi3. The directory “home/osmc/spotify-connect-web-chroot” does not exist after running that script. I had the exact same behaviour on my own RPi2.

So I started to modify your .sh script and it worked flawlessly like this:

#!/bin/bash
set -e

DIR=~/spotify-connect-web-chroot

if [ "$1" == "install" ]; then
        mkdir -p spotify-connect-web-chroot
        cd spotify-connect-web-chroot
        curl http://spotify-connect-web.s3-website.eu-central-1.amazonaws.com/s$
else
        trap "sudo umount $DIR/dev $DIR/proc" EXIT
        sudo mount --bind /dev $DIR/dev
        sudo mount -t proc proc $DIR/proc/
        sudo cp /etc/resolv.conf $DIR/etc/
        sudo chroot $DIR /bin/bash -c "cd /usr/src/app && python main.py $*"
fi

I only had to fill in the directory name in the mkdir, cd and curl command. I believe the bug is the parameter DIR uses ~/ which does not work for mkdir, cd and curl.

Now it works flawlessly on a cleanly installed RPI3 (with OSMC june 2016).