Spotify Connect

Here we go …

aplay -l

**** List of PLAYBACK Hardware Devices **** card 0: sndrpihifiberry [snd_rpi_hifiberry_dac], device 0: HifiBerry DAC HiFi pcm5102a-hifi-0 [] Subdevices: 1/1 Subdevice #0: subdevice #0 card 1: ALSA [bcm2835 ALSA], device 0: bcm2835 ALSA [bcm2835 ALSA] Subdevices: 8/8 Subdevice #0: subdevice #0 Subdevice #1: subdevice #1 Subdevice #2: subdevice #2 Subdevice #3: subdevice #3 Subdevice #4: subdevice #4 Subdevice #5: subdevice #5 Subdevice #6: subdevice #6 Subdevice #7: subdevice #7 card 1: ALSA [bcm2835 ALSA], device 1: bcm2835 ALSA [bcm2835 IEC958/HDMI] Subdevices: 1/1 Subdevice #0: subdevice #0

aplay -L null Discard all samples (playback) or generate zero samples (capture) default:CARD=sndrpihifiberry snd_rpi_hifiberry_dac, Default Audio Device sysdefault:CARD=sndrpihifiberry snd_rpi_hifiberry_dac, Default Audio Device dmix:CARD=sndrpihifiberry,DEV=0 snd_rpi_hifiberry_dac, Direct sample mixing device dsnoop:CARD=sndrpihifiberry,DEV=0 snd_rpi_hifiberry_dac, Direct sample snooping device hw:CARD=sndrpihifiberry,DEV=0 snd_rpi_hifiberry_dac, Direct hardware device without any conversions plughw:CARD=sndrpihifiberry,DEV=0 snd_rpi_hifiberry_dac, Hardware device with all software conversions default:CARD=ALSA bcm2835 ALSA, bcm2835 ALSA Default Audio Device sysdefault:CARD=ALSA bcm2835 ALSA, bcm2835 ALSA Default Audio Device dmix:CARD=ALSA,DEV=0 bcm2835 ALSA, bcm2835 ALSA Direct sample mixing device dmix:CARD=ALSA,DEV=1 bcm2835 ALSA, bcm2835 IEC958/HDMI Direct sample mixing device dsnoop:CARD=ALSA,DEV=0 bcm2835 ALSA, bcm2835 ALSA Direct sample snooping device dsnoop:CARD=ALSA,DEV=1 bcm2835 ALSA, bcm2835 IEC958/HDMI Direct sample snooping device hw:CARD=ALSA,DEV=0 bcm2835 ALSA, bcm2835 ALSA Direct hardware device without any conversions hw:CARD=ALSA,DEV=1 bcm2835 ALSA, bcm2835 IEC958/HDMI Direct hardware device without any conversions plughw:CARD=ALSA,DEV=0 bcm2835 ALSA, bcm2835 ALSA Hardware device with all software conversions plughw:CARD=ALSA,DEV=1 bcm2835 ALSA, bcm2835 IEC958/HDMI Hardware device with all software conversions

Reading the issue I tried to comment out the use of mixer:

in connect.py:

#mixer_volume = int(mixer.getvolume()[0] * 655.35) #lib.SpPlaybackUpdateVolume(mixer_volume)

in console_callbacks.py:

#mixer = alsa.Mixer(args.mixer)

Without success :frowning:

I don’t know exactly what’s going wrong.

Like in the issue, did you execute the command: amixer ?
If yes, and you get no results. Try this guideline: hifiberry.com/guides/mixer-settings/

Did you already test with the command line if the Hifiberry gives any sound?

The alsa-utils are already installed and using each of the commands brings me always the following message:

amixer: Unable to find simple control …

Starting “alsamixer” shows me the message “This sound device does not have any controls.”

No, I didn´t. How can I do that?

The DAC itself works. I use it with volumio very well (stream music via Airplay).

I resolved my issue with the
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

error message by reverting back to the 3.18.5-v7+ kernel after having updated it. After that spotify connect is now starting and working fine.

The only issue I am now having is that since then the volume control in volumio does not work. I can control the volume from spotify when using connect but when playing things through the volumio web interface the volume control does nothing.

I presume it is that connect is not releasing the mixer control when it is not playing a track but I am unsure how to resolve this.

I am running a HiFiBerry DAC+ Pro on a RPi2 btw.

Hello Everybody,

Thank you very much for all information provided in this thread.
I got Spotify Connect running without a problem, including autostart.

Is there a possible way of resampling audio from it? In volumio I have it set to 32/192, but via spotify connect it goes directly to 44. I like upsampling and would like to stick to that option. Thank you in advance for help.

As off topic, I might have a small advise if someone would like to install chroot directly in our user home folder, instead of root.

  1. Follow first two steps of instllation, starting in our home directory i.e. /home/pi:

curl -O http://spotify-connect-web.s3-website.eu-central-1.amazonaws.com/spotify-connect-web.sh chmod u+x spotify-connect-web.sh

  1. Run:

sudo nano /home/pi/spotify-connect-web.sh

3.Change DIR to desired one, example fo “pi” user:

DIR=/home/pi/spotify-connect-web-chroot

CTRL + X and Y and enter for Save and Quit

  1. Now install:
/home/pi/spotify-connect-web.sh install

(change “pi” to your username if neccessary)

sudo cp spotify_appkey.key  /home/pi/spotify-connect-web-chroot/usr/src/app/
  1. And simply run
./spotify-connect-web.sh --username 12345678 --password xyz123 --bitrate 320

There might be a different way to install, however this is what I have been struggling with and it might be the case for other users. I saw posts of people copying from root to home directory (this is what I did for the first time, as I could now make it autorun after restart).

I also had problems with the --mixer switch. I performed the install as written in the readme on github. I think the --mixer problems occur on the analog hifiberryDAC. I use it with an RPi B. My fix is to comment all code using the mixer and volume. And I got it working.

connect.py


#from console_callbacks import audio_arg_parser, mixer, error_callback, connection_callbacks, debug_callbacks, playback_callbacks, playback_setup
from console_callbacks import audio_arg_parser, error_callback, connection_callbacks, debug_callbacks, playback_callbacks, playback_setup

#        mixer_volume = 1 #int(mixer.getvolume()[0] * 655.35)
#        lib.SpPlaybackUpdateVolume(mixer_volume)

console_callbacks.py

#audio_arg_parser.add_argument('--mixer', '-m', help='alsa mixer name for volume control', default=alsa.mixers()[0])

#mixer = alsa.Mixer(args.mixer)

#@ffi.callback('void(uint16_t volume, void *userdata)')
#@userdata_wrapper
#def playback_volume(self, volume):
#    print "playback_volume: {}".format(volume)
#    mixer.setvolume(int(volume / 655.35))

playback_callbacks = ffi.new('SpPlaybackCallbacks *', [
    playback_notify,
    playback_data,
    playback_seek#,
    #playback_volume

I’m still not 100% sure if there isn’t an more elegant way. So that is still under investigation. It should be possible to pass an working playback_volume if the mixer is not available.

But for now the result is a working spotify:connect and with that i’m pleased. Tomorrow I will put the whole config to a more thorough test.

Hi twirre,

I tried it as well but without luck.

Can you tell me what happens if you start “amixer” or “alsamixer” from console? Is “alsamixer” telling you “This sound device does not have any controls.”?

amixer gives no response. It is installed

root@volumio:~# amixer -v amixer version 1.0.27.2 root@volumio:~# amixer root@volumio:~#

alsamixer gives a gui. I installed in my search for the solution.

I am under the imperession that the problem is the DAC itself. I t doesnt support volume_controle. For example i had (and have) no problems playing spotify playlists through the volumio gui. If it really is an mixer problem, this also shouldnt be working (for a far a i understand it).
alsamixer.png

what is the message you get, when starting ./spotify-connect-web.sh --user abc --password 123 --name rpiVolumio --bitrate 320

After disabling all the lines you mentioned I get the following error:

Loading Spotify library…
Traceback (most recent call last):
File “main.py”, line 11, in
from connect import Connect
File “/usr/src/app/connect.py”, line 12, in
class Connect:
File “/usr/src/app/connect.py”, line 13, in Connect
def init(self, error_cb = error_callback):
NameError: name ‘error_callback’ is not defined

Did you disable “#playback_volume” only in the “playback_callbacks” in file “console_callbacks”?

Ok, I got it now :smiley: … I disabled a bit too much :confused:

Thank you very much twirre for your very usefull hint of disabled items in both files!!!

the last comment is indeed a bit tricky. I tried to keep the code as original as posible. Therefor I had to comment the #, at the end of the line before the playback_volume line.

Hi all,

first of all, thank for this great work, bringing Spotify Connect to Volumio!!

I’ve installed the latest version (chroot) from github “Fornoth/spotify-connect-web” and it works perfect. Beside Spotify Connect I’m using volumio’s UPNP renderer with JRivers - JRemote to stream from my local music library. Switching between the two apps is easily accomplished using the stop button and than changing the application.

Now, I have started to think about controlling volumio with a IR remote control using lirc. For that case I’m looking for a possibility to stop the spotify player and for example to start mpc with a radio stream.

So, is there a possibility to stop the spotify player without killing and restarting the whole process?

Dear friends. I solved this issue:

I did the following steps:

  1. I did a plain new installation of Volumio 1.55 (flashed a new SD-card)

  2. I deleted the original console_callbacks.py in the /home/volumio/spotify-connect-web-chroot/usr/src/app/ folder and substituted it with the console_callbacks.py from https://github.com/Fornoth/spotify-connect-web/blob/855b92b49555cdcc11d0ab4c71866475cd7c9499/console_callbacks.py. So far I understand this step is important. The console_callbacks.py from Fornoth gives the mixer free when the spotify-connect playback is stopped. In doing so, other applications (e.g., mpd) are able to ‘grab’ the mixer and to play music. The original console_callbacks.py still ‘owns’ the mixer even when spotify-connect playback is stopped. Therefore, other applications are not able to playback music because the mixer is ‘blocked’. (Please correct me if I am wrong.)

  3. I modified the connect.py in the /home/volumio/spotify-connect-web-chroot/usr/src/app/ folder.
    I changed the line:

 mixer_volume = int(mixer.getvolume()[0] * 655.35)

to

 mixer_volume = 1 #int(mixer.getvolume()[0] * 655.35)

The mixer volume has to be set to 1 because the hifiberry digi has no volume control. It simply gives out the bit perfect data via the optical or electrical port. The data have to be transformed to an analog signal by an external digital-analog-converter (DAC; in my case a Musical Fidelity V90DAC which is connected via coax through the electrical output). The volume cannot be changed via the spotify-app. It has to be changed directly at your power amplifier.

  1. I disabled the onboard soundcard (analog and HDMI) of the raspberry pi.
    I changed this line in the /etc/modules:
snd_bcm2835

to

#snd_bcm2835
  1. Do a reboot.

  2. I use this startup command:

/home/volumio/spotify-connect-web.sh --name 'livingroom' --username 'xxx' --password 'xxx' --bitrate '320'

Conclusion: I think, step 3 is the most important step. However, step 2 is also important if you want to use spotify-connect alongside with other playback applications (e.g., mpd).

I hope this is helpful for you. Thank you very much for writing this awesome feature. It is a great pleasure to playback spotify music on your raspberry pi - hifiberry digi system and controlling it over the spotify app on your smart phone.

Best regards,
domars

isn’t the line 215 in console_callbacks.py giving any trouble?

mixer.setvolume(int(volume / 655.35))

Ill try your solution this weekend.

I tried this with success, i also have the hifiberry digi+ and changing volume from the phone works great. BUT, sound quality is taking a hit. Wife heard it as well so its not in my head. Or is it?

No, this setting does not cause any problems.

Congratulations! :slight_smile:

I have two set-ups (one for my livingroom and one for my bedroom):

  1. Raspberry Pi 2–> Hifiberry Digi + --> Musical Fidelity V90 DAC (connected via coax) --> Yamaha AS 700 power amplifier
  2. Raspberry Pi B Rev 2 --> Hifiberry Digi --> Wolfson WM8718 DAC integrated in my Onkyo A9050 power amplifier (connected via optical output)

For both set-ups I disabled the volume control in the Volumio settings and I set the mixer_volume to 1 in the connect.py:

I control the volume directly at my power amplifier (analog volume control). If I compare a loosy 320 kbit ogg vorbis file from Spotify with a lossless flac file played in Volumio (I have several recordings that are available on Spotify and in my local music collection [lossless flac rips from CDs I own]) I can’t hear a big difference. I think that in a blind test I am not able to tell whether it is a lossy compressed 320 kbit ogg vorbis file from Spotify or a lossless flac file from my local music collection. So if the volume control in the Spotify app degrades your sound quality, it might be the case that this is caused by some kind of software volume control. I heard that software volume control can affect the sound quality (Is anybody here who can explain why?) . As far as I know from the Hifiberry forum, there is no hardware volume control available in the Hifiberry Digi. See this post from Daniel (a developer from the Hifiberry team https://support.hifiberry.com/hc/en-us/community/posts/201845971-RPI-2-amp-Digi-Hardware-volume-in-Rune-Audio-):

I don’t know if the Hifiberry Digi + has a hardware volume control. Does anybody know this? In your case, it might be helpful to disable the volume control in volumio and directly use the analog volume control in your power amplifier. This might be less comfortable but may increase sound quality.

Here is an interesting article about volume control in general: https://support.hifiberry.com/hc/en-us/articles/206619149-Volume-control-hardware-software-analog-digital.

Please correct me if I got something wrong. Have a nice weekend,
domars

Hi,

I have installed on my RPi 1B 512mb Volumio 1.55 and the spotify connect chroot.
My RPi 1B is connected with hdmi to my yamaha receiver. I use the standard hdmi audio output.
I always keep the RPi alive, but my other AV devices are going into standby mode and the tv is off during the night
spotify connect Works like a charm however i have one problem. When i turn on the all av devices in the morning, there is no sound on spotify connect device but the spotify connect device is still visible. Only a restart is solving the problem. Without the spotify connect chroot, volumio has no such problem.

Additional: I also have a RPi kodi/openelec attached to the Receiver

Anyone an idea?

In some cases the spotify connect service disappears from my network, so I can’t find it on other devices in Spotify. The spotify connect web service is still running. I’ve to manually restart the service to make the service available again.

Does anyone experience this problem too?