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

@zilexa,

You have actually written my steps in a script? That would be wonderful! Great job.

@karower,

You’re looking for a way to release the ALSA device. Look at the latest version 0.0.3 (now added as 20c). It should work.

@honzejk,

Can jou explain what you did? I could add it to the Howto.

@Richard_A_Billings,

I assume this has something to do with it:
ALSA lib confmisc.c:768:(parse_card) cannot find card ‘default’
ALSA lib conf.c:4259:(sndconfig_evaluate) function snd_func_card_driver returned error: No such device
ALSA lib confmisc.c:392:(snd_func_concat) error evaluating strings
ALSA lib conf.c:4259:(sndconfig_evaluate) function snd_func_concat returned error: No such device
ALSA lib confmisc.c:1251:(snd_func_refer) error evaluating name
ALSA lib conf.c:4259:(sndconfig_evaluate) function snd_func_refer returned error: No such device
ALSA lib conf.c:4738:(snd_config_expand) Evaluate error: No such device
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM default:CARD=default
Unable to acquire device: No such device [default:CARD=default]

Try adding -o hw:0 in the commandline.
Does that help?

Yes I did, along with a few other howto’s (SyncThing, OpenVPN, Flexget, DynamicDNS, Kodi library sources and basic Transmission config, like user/PW but also to scan every download individually to your Kodi library). You can simply add a 0 or a 1 at the top of the script to decide what to install.

But the post is hidden for several reasons so I thought no one could see it. Here is the indirect link:

https://gist.github.com/zilexa?direction=asc&sort=updated

It’s called OSMCautosetup.sh, click on it, then find the “raw” button at the top right, copy that link and download the script using wget URL then edit it (change 1s to 0s and fill the required config questions) via nano OSMCautosetup, save with CTRL+O, exit with CTRL+x and then run it via sudo bash OSMCautosetup.sh.

In the future all of this would be part of OSMC app store or Installation Wizard.

Looking forward to that if you would like to work on this.

Sam

0,0 coding experience and after a course at university realised it’s nothing for me. Copy pasting and googling if statements was really a huge milestone for me. I automated windows installations in the past (in my spare time) but again, I simply executed or copy pasted stuff from a forum.

OSMC deserves more true developers, dedicated to the task.

In July I will be back home and definitely willing to get mixed up into this but I would really need a guide to get started and some assistance when I get stuck.

Until July I am unable to help.
I have donated to several projects in the past (big amount to Xbian…) always with the message to enhance usability, more friendly for noobs to install etc. Always felt the donation merely kept the project alive, nothing more. Learned from my mistakes now I wait at least 2 years before donating.

My ultimate goal: have an open source based media hub at home that is so easy to install and ready to use, you can explain how to get started and reach a ‘netflix like’ experience in a bar to a bunch of absolute noobs and it will actually make sense to half of the group (the rest is doomed, or very happy because of their ignorance and don’t need a media center).

@zatarra Thank you very much for this Howto.
It took me some time to get it working by combining your code with the code from axel. I see you’ve update your intructions to include Fornoth now as well.
After then I could see OSMC in Spotify, but I heard no sound. With your latest update with assigning the hardware it now works!!

I see people like @yotic having trouble with obtaining their appkey.
Indeed the website now shows a link to a google docs form (Direct link)
I’ve filled in the form and only after 3 weeks I got my key, so this can take some time. Mind you, you’ve to fill in your exact username and e-mail associated with your account, so authentication with e.g. facebook doesn’t work.

After I’d received my appkey, the attached appkey didn’t work as well. I had to convert the BASE64 APPKEY in the body of the mail to a binary file. I’ve read this is sometimes the case. You can convert it e.g. here: Base64 Online - base64 decode and encode

@Sjohn21,
Thanks for the useful addition. Nice to know the status for requiring the spotify key. I’m glad it still works, although not as easy as it was.

Hey Zatarra, thank you very much for posting this. I now have what I have wanted for about a year, a properly working Spotify Connect device in locations where I want it!

It was pretty clear, but I came across a couple of things that I think are worth pointing out to save time:

  1. I did not hear audio straight away when I followed your tutorial, so I started debugging in Kodi to discoverdthe device that was being used as the audio renderer. It turns out that in the Kodi release I used (downloaded it yesterday) the command aplay is not available out of the box, and instead returns an ‘unknown command’ or similar response. To resolve this, you need to install alsa tools. A useful thread to read is this one: http://forum.xbian.org/thread-3034-post-29287.html.

In particular, this response:

  1. In step 10., where you suggest a good test is to run the script directly as follows:

./spotify-connect-web.sh -o hw:0 --username [12345678] --password [xyz123] --bitrate 320 --name [any name]

I discovered two things:
a. User name is not the numerical username that Spotify ultimately uses, but your e-mail address.
b. It was not clear (at least for me) that the –name switch allows you to define the device name that appears in Spotify applications on phones and web browsers, which allows users to select which device is to be the listening device.
c. Also, the string following –name cannot be multiple words, even if they are enclosed in quotation marks. It has to be alphanumeric characters, no spaces, single string. The service start up appears to fail if any other strings are used in addition.

Other than that, a great tutorial, and good result. Thank you for taking the time to prepare it.

Hi @zatarra and others

A few things that I worked out when installing on my RPi1, I expect it should apply also to RPi2/3:

  1. To get the app_key from the Volumio plugin, steps 5-9 can be replaced by this simple command:

sudo wget -P ~/spotify-connect-web-chroot/usr/src/app https://github.com/balbuze/volumio-plugins/raw/master/plugins/music_service/volspotconnect/spotify-connect-web/spotify_appkey.key

  1. In step 18 you can remove the “.service” extension on all lines, it makes no difference. You can also skip the chmod command.

  2. I also noticed that if I stop and start the service, the /dev and /proc mounts are duplicated. It’s probably not a practical problem to anyone, but not pretty. You can check this by doing the following when the service is running:

mount | grep spotify
sudo systemctl stop scs
sudo systemctl start scs
mount | grep spotify

My solution was to check if the mount already exists before mounting. To do so I edited the script spotify-connect-web.sh and replaced

sudo mount --bind /dev $DIR/dev
sudo mount -t proc proc $DIR/proc/

with

if ! mount | grep -q “$DIR/proc” ; then sudo mount -t proc proc $DIR/proc/; fi
if ! mount | grep -q “$DIR/dev” ; then sudo mount --bind /dev $DIR/dev;fi

Installing on RPi1 with OSMC and HifiBerry DAC

I needed to do two things to get the SpotifyConnect to run on my system, probably caused by the fact that the hifiberry doesn’t have any hardware mixer.

1 If not done already, select hifiberry_dac as ‘soundcard overlay’ in PiConfig and restart the system.

2 Before step 10 in the Howto (starting the service), you need to create a software mixer (This is copied from the Volumio plugin referred to above):
First check that the HifiBerry has HW index 0:

osmc@osmc:~$ cat /proc/asound/cards
0 [sndrpihifiberry]: snd_rpi_hifiber - snd_rpi_hifiberry_dac
snd_rpi_hifiberry_dac

If you have more than one card active you may get a response like this:

volumio@volumio:~$ cat /proc/asound/cards
0 [ALSA ]: bcm2835 - bcm2835 ALSA
bcm2835 ALSA
1 [sndrpihifiberry]: snd_rpi_hifiber - snd_rpi_hifiberry_dac
snd_rpi_hifiberry_dac
volumio@volumio:~$

In the last example the HifiBerry has index 1 and you would need to replace ‘plughw:0,0’ with ‘plughw:1,0’ and ‘card 0’ with ‘card 1’ in asound.conf below

Then create the alsa configuration file:

osmc@osmc:~$ sudo nano ~/spotify-connect-web-chroot/etc/asound.conf

Paste in:

pcm.softvolume {
    type             plug
    slave.pcm       "softvol"
}

pcm.softvol {
    type            softvol
    slave {
        pcm         "plughw:0,0"
    }
    control {
        name        "SoftMaster"
        card        0
        device      0
    }
max_dB 0.0
min_dB -50.0
resolution 100
}

Ctrl-x y Enter to save and exit

[Edit] It seems now that you need the same asound.conf both in the normal /etc and in the chroot path for this to work. Don’t ask me why. So also run:

osmc@osmc:~$ sudo cp ~/spotify-connect-web-chroot/etc/asound.conf /etc

Then in step 10 and step 15, replace:
-o hw:0
with:
–playback_device ‘softvolume’ --mixer ‘SoftMaster’

3 No ‘default mixer’ issue
If step 10-11 worked fine and the service runs as expected, you can skip this part.
Restart the system
Run the amixer command, you should get one of these two outputs:

osmc@osmc:~$ amixer
osmc@osmc:~$
or
osmc@osmc:~$ amixer
Simple mixer control ‘SoftMaster’,0
Capabilities: volume
Playback channels: Front Left - Front Right
Capture channels: Front Left - Front Right
Limits: 0 - 99
Front Left: 69 [70%]
Front Right: 69 [70%]
osmc@osmc:~$

(you need to have alsa-utils installed. If you get “Command not found”, then run sudo apt-get update and sudo apt-get install alsa-utils and then amixer)

If you get the second type of response (doesn’t really matter which mixer name it prints) you don’t have the mixer issue and need to search for other solutions to any problems. But if you got the first type of response there is no mixer at all available. Unfortunately the spotify service assumes that there is at least one mixer available (even though we supply another mixer which it will use) otherwise it will fail to start.

Solution 1
Note: This solution hopefully works, but is never tested on a clean install.
Run the application ‘speakertest’, using our new software mixer:

osmc@osmc:~$ speaker-test -D softvolume

speaker-test 1.0.28

Playback device is softvolume
Stream parameters are 48000Hz, S16_LE, 1 channels
Using 16 octaves of pink noise
Rate set to 48000Hz (requested 48000Hz)
Buffer size range from 16 to 131072
Period size range from 8 to 65536
Using max buffer size 131072
Periods = 4
was set period_size = 32768
was set buffer_size = 131072
0 - Front Left
Time per period = 0.063774
0 - Front Left
Time per period = 2.735002
0 - Front Left
^CTime per period = 0.007481

If you have amplifiers and speakers connected you will hear a white noise.
Interrupt with Ctrl-C after a couple of seconds.
Then run ‘amixer’ again. Now you should get the second type of output. If not, go on to solution 2.

Solution 2
This solution requires to edit one of the python files:

sudo nano ~/spotify-connect-web-chroot/usr/src/app/console_callbacks.py

Edit the row:
audio_arg_parser.add_argument('--mixer', '-m', help='alsa mixer name for volume control', default=alsa.mixers()[0])
to (‘NoDefault’ could be changed to any string you like):
audio_arg_parser.add_argument('--mixer', '-m', help='alsa mixer name for volume control', default='NoDefault')
Ctrl-x y Enter to save and exit

Now the reset of the original howto should work fine.

Hi guys, after the latest january update on my vero2 yesterday, I now noticed that spotify connect doesnt work anymore. Well to be precise it starts playing music but after short time playback hangs and osmc pretty much freezes. No ssh con., no kodi interaction possible…
I’m definetly NOT on the newest version, I guess I’ll have to read through the replies here to update it.
Just wanted to know if anyone also experiences this with the newest version of spoti web connect server?

I now tried to reinstall with @zilexa s scriot and I get this: (tried to run the script as root and as user osmc)

Any ideas?

@Sound,
Good to hear you got it to work.

True, the alsa-utils, such as aplay and amixer, are not standard included in the OSMC standards. It’s quite easy to install them with the commands

sudo apt-get update
sudo apt-get install alsa-utils

Also noted by @keab

But in most cases, you don’t need them (not with the regular Rpi output).

@keab,

Thanks for the useful addition. I changed step 5-9 as you suggested.
The other steps might be neater, but the current steps work. So I leave them unchanged to prevent it for getting more complicated.

May I suggest that you share this information at Github with Fornoth to improve the next version of this spotify-connect-server?

Regarding your post about the Hifiberry DAC, I suppose it didn’t work out of the box ;). Your actions are a bit to complicated for me (I’m a Linux noob), but I like to add your findings to the Howto. Could you change your actions to a few easy steps so I can add it to the Howto?
Could the things you have done also make audio through bluetooth work?

@trohn_javolta,
Sorry, your problems are not familiar to me. Can’t help you there… I’m to much a noob to really understand what is going on there.

Hi,

great work!
I got it running so far, but i can’t control the Volume.
I am using an USB-DAC connected to an AMP.
After playing a bit an set -o hw:1 playback works, but as i said, i can’t controll volume.

Any Ideas?

Thanks

Is Spotify Cconnect supposed to work with other Spotify users then the username specified during installation?

It did work with different users when I installed Spotify Connect on Volumio. But on the R Pi 2 with OSMC it only works with my Spotify account. Spotify Connect won’t show up for others Spotify users on the same wifi network.

https://github.com/Fornoth/spotify-connect-web/issues/91#issuecomment-253795631

1 Like