WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Spotify connect (librespot) on piCore  (Read 5179 times)

Offline Gerrelt

  • Full Member
  • ***
  • Posts: 178
Spotify connect (librespot) on piCore
« on: February 16, 2019, 11:06:48 AM »
Hi all,

I've got Spotify connect with librespot working on piCore, and I wanted to share how I did it.
With librespot running, your raspbery pi will show up in the Spotify app under "devices available".
When selected, the song will be played on your raspberry instead of your phone.
(NOTE: I believe this does not work with a free spotify account)

Librespot uses "libportaudio2" which wasn't available on piCore, so I compiled it, and made a .tcz package for it.
To get it all running, execute these commands:

Code: [Select]
mkdir librespot
cd librespot
# libportaudio2 compiled and packaged by me, and source downloaded from:
#     http://www.portaudio.com/download.html
wget http://www.gerrelt.nl/RaspberryPi/libportaudio2.tcz -P /mnt/mmcblk0p2/tce/optional
sudo echo "libportaudio2.tcz" >> /mnt/mmcblk0p2/tce/onboot.lst
# librespot compiled by me, and source downloaded from:
#     https://github.com/librespot-org/librespot
wget http://www.gerrelt.nl/RaspberryPi/SpotifyRadio/librespot.tar.gz
tar -xvzf librespot.tar.gz
sudo mv librespot /mnt/mmcblk0p2/tce
chmod u+x /mnt/mmcblk0p2/tce/librespot

To start it at boot, you will have to choose a soundcard first.
Execute:
Code: [Select]
aplay -lor
Code: [Select]
cat /proc/asound/cards
And see wich soundcard number and device number you want to use.

Open bootlocal.sh:
Code: [Select]
sudo nano -\$\icwS /opt/bootlocal.sh
And add this line to the end:
Code: [Select]
/mnt/mmcblk0p2/tce/librespot --name YourSpotifyConnectDevicename --cache /tmp --bitrate 320 --initial-volume 100 --backend alsa --device hw:0,0 > /dev/null 2>&1 &
Now, change "--device hw:0,0" to the choosen soundcard and device number, this example uses soundcard 0 and device 0.

Also check if you want to set the initial volume to 100%. If you adjust volume by a physical volume knob, you probably want it set to 100. If you use a software "volume knob", you probaly want to set it to something a lot lower.  ;D
See option "--initial-volume 100" to change it.

You will also want to change "--name YourSpotifyConnectDevicename" to give your device a recognizable name.

Exit nano with CTRL-X, save the file, and make all your changes persistent by executing:
Code: [Select]
filetool.sh -b
Reboot your raspberry pi, and when booted, it should appear under "devices available".

Enjoy! 8)


« Last Edit: February 16, 2019, 11:11:20 AM by Gerrelt »
my Raspberry Pi page: http://raspberry.gerrelt.nl

Offline Gerrelt

  • Full Member
  • ***
  • Posts: 178
Re: Spotify connect (librespot) on piCore
« Reply #1 on: April 28, 2019, 12:31:47 PM »

For who is interested in this...:

I had some problems with tracks not starting or skipping to the end of the songs, so I compiled Librespot again with the latest sources.
This solved it for Raspbian, but not for piCore.
It turned out the problem was that I didn't set the timezone on my piCore installations. You can check by executing the "date" command and compare it to the actual time.
After some (long) searching I found how to set the timezone.

I set it like this:

Code: [Select]
mount /dev/mmcblk0p1
Open cmdline.txt it in nano:

Code: [Select]
sudo nano -\$\icwS  /mnt/mmcblk0p1/cmdline.txt
And add to the end (with a space before it to seperate it from the other settings):

Code: [Select]
tz=CET-1CEST,M3.5.0,M10.5.0/3​(NOTE: this is for Europe/Amsterdam)
Save and close the file and do a backup:

Code: [Select]
filetool.sh -b
After a reboot the timezone was correct and Spotify connect worked correctly again.

Sidenote, you can check wat the tz string should be if you have a Raspbian installation:
Code: [Select]
cat /usr/share/zoneinfo/Europe/AmsterdamThis will produce some garbage, but in between it will mention the timezone string.
my Raspberry Pi page: http://raspberry.gerrelt.nl

Offline mickeyarthy

  • WikiUser
  • *
  • Posts: 1
Re: Spotify connect (librespot) on piCore
« Reply #2 on: June 08, 2019, 08:32:32 PM »
This feature makes spotify playback easy with picoreplayer.
Thanks to Mr. Gerrelt for sharing this setup.

Offline Zizico2

  • WikiUser
  • *
  • Posts: 1
Re: Spotify connect (librespot) on piCore
« Reply #3 on: December 28, 2019, 08:47:44 PM »
I have followed your steps. It doesn't start on boot. If I run '''/mnt/mmcblk0p2/tce/librespot --name YourSpotifyConnectDevicename --cache /tmp --bitrate 320 --initial-volume 100 --backend alsa --device hw:0,0 > /dev/null 2>&1 &''' manually (sudo) I get the desired result, but bootlocal doesn't seem to be able to start librespot...

Is bootlocal called to early?! idk...
« Last Edit: December 28, 2019, 08:52:13 PM by Zizico2 »

Offline RomanoFX

  • WikiUser
  • *
  • Posts: 5
Re: Spotify connect (librespot) on piCore
« Reply #4 on: January 05, 2020, 10:52:54 AM »
On boot, I got the same issue. It only works when I launch it manually. Do you have an idea?

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 7934
Re: Spotify connect (librespot) on piCore
« Reply #5 on: January 05, 2020, 11:44:25 AM »
Hi Zizico2 & RomanoFX
Try changing this:
Code: [Select]
/mnt/mmcblk0p2/tce/librespot --name YourSpotifyConnectDevicename --cache /tmp --bitrate 320 --initial-volume 100 --backend alsa --device hw:0,0 > /dev/null 2>&1 &to this:
Code: [Select]
/mnt/mmcblk0p2/tce/librespot --name YourSpotifyConnectDevicename --cache /tmp --bitrate 320 --initial-volume 100 --backend alsa --device hw:0,0 > /tmp/errors.txt 2>&1 &
Then see if there are any clues in  /tmp/errors.txt.

Offline RomanoFX

  • WikiUser
  • *
  • Posts: 5
Re: Spotify connect (librespot) on piCore
« Reply #6 on: January 25, 2020, 05:26:50 AM »
Thank you Rich for helping us!
Please find the error log

Quote
INFO:librespot: librespot 14721f4 (2019-03-27). Built on 2019-04-06. Build ID: $
WARN:<unknown>: Failed to register IPv6 receiver: Os { code: 97, kind: Other, m$
WARN:<unknown>: dropping truncated packet from V4(192.168.0.1:5353)
INFO:librespot_core::session: Connecting to AP "gew1-accesspoint-a-z4wt.ap.spot$
INFO:librespot_core::session: Authenticated as "*********" !
INFO:librespot_playback::audio_backend::alsa: Using alsa sink
INFO:librespot_core::session: Country: "FR"
INFO:librespot_playback::player: Loading track "I Will Follow You Into The Dark
2 minutes after
Quote
INFO:librespot_playback::player: Track "I Will Follow You Into The Dark" loaded
WARN:<unknown>: dropping truncated packet from V4(192.168.0.1:5353)

It takes 2 minutes to play music. I can ensure the connection is good (wired)

Thank you

Offline RomanoFX

  • WikiUser
  • *
  • Posts: 5
Re: Spotify connect (librespot) on piCore
« Reply #7 on: January 25, 2020, 05:55:09 AM »
After few attempts, few reboots, it works well!
I just added bluetooth player, it's perfect!  ;D

Quote
/mnt/mmcblk0p2/tce/librespot --name "Spotify Client" --cache /tmp --bitrate 32
0 --initial-volume 70 --backend alsa --device hw:0,0 > /tmp/errors.txt 2>&1 &

bluealsa-aplay 00:00:00:00:00:00 > /tmp/error_bt.txt 2>&1 &

Offline RomanoFX

  • WikiUser
  • *
  • Posts: 5
Re: Spotify connect (librespot) on piCore
« Reply #8 on: January 25, 2020, 12:53:27 PM »
It works after I launch bluetooth playing or waiting few minutes.
The sound begins to play when that message occurs in dmesg logs
Quote
[  299.364909] random: crng init done
[  299.364919] random: 4 urandom warning(s) missed due to ratelimiting
I am looking for haveged but still not found. An idea?

Thank you

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 583
Re: Spotify connect (librespot) on piCore
« Reply #9 on: January 25, 2020, 07:08:31 PM »
Your running out of random.   You will need to use rngd to feed random from the arm hw device.

https://github.com/nhorman/rng-tools

It’s got quite a few dependencies.  Most are available in extensions.
« Last Edit: January 25, 2020, 07:12:43 PM by Paul_123 »

Offline RomanoFX

  • WikiUser
  • *
  • Posts: 5
Re: Spotify connect (librespot) on piCore
« Reply #10 on: January 26, 2020, 12:08:44 AM »
Thank you for your message Paul.
I found rng-tools.tcz in repo but no random sources are available (tpm or nist) when I run it

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 583
Re: Spotify connect (librespot) on piCore
« Reply #11 on: January 26, 2020, 05:35:10 AM »
It should use. /dev/hwrng

Offline chemanork

  • Newbie
  • *
  • Posts: 3
Re: Spotify connect (librespot) on piCore
« Reply #12 on: July 02, 2020, 12:41:33 AM »
Dear Gerrelt,

Thank you for preparing this solution and leave it available for the rest of us. I thought the same and found out through Google that someone else already did it!

I follow all the steps, first problem I had is that "aplay -l" and "cat /proc/asound/cards" did not work. I investigated a little and installing alsa and alsa-utils made it work.

Second problem is that both alsa and alsa-utils did not start in bootlocal.sh, I had to set them in /home/tc/.X.d/startupscript.sh in order to work.

The last problem I could not figure out yet is that "/mnt/mmcblk0p2/tce/librespot --name YourSpotifyConnectDevicename --cache /tmp --bitrate 320 --initial-volume 100 --backend alsa --device hw:0,0 > /dev/null 2>&1 &" does not start in neither bootlocal.sh or startupscript.sh. But if I run it in terminal it starts working.

What could it be?

Offline chemanork

  • Newbie
  • *
  • Posts: 3
Re: Spotify connect (librespot) on piCore
« Reply #13 on: July 03, 2020, 03:16:10 PM »
I made it work. With a sleep command before librespot. It seemed libasound library was not loaded yet. With 3 seconds made the trick.

What is strange now is that if I disconnect from power the rbpi, when I turn it on again no sound will output. I have to reboot it in order to work...

Offline chemanork

  • Newbie
  • *
  • Posts: 3
Re: Spotify connect (librespot) on piCore
« Reply #14 on: July 07, 2020, 12:32:53 AM »
Well, finally it works even when I unplug the rpi. These 2 lines reset the alsa driver:

sudo modprobe snd_bcm2835
sudo amixer cset numid=3 2

Found it here: newbielink:https://www.raspberrypi.org/forums/viewtopic.php?t=246431 [nonactive].

Regarding my problems with running alsa and alsa-utils, my problem was that I had not include them in onboot.lst. Now librespot works without x server in bootlocal.sh