Tiny Core Linux

Tiny Core Base => Raspberry Pi => Topic started by: Gerrelt on February 16, 2019, 02:06:48 PM

Title: Spotify connect (librespot) on piCore
Post by: Gerrelt on February 16, 2019, 02:06:48 PM
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)


Title: Re: Spotify connect (librespot) on piCore
Post by: Gerrelt on April 28, 2019, 03: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.
Title: Re: Spotify connect (librespot) on piCore
Post by: mickeyarthy on June 08, 2019, 11:32:32 PM
This feature makes spotify playback easy with picoreplayer.
Thanks to Mr. Gerrelt for sharing this setup.
Title: Re: Spotify connect (librespot) on piCore
Post by: Zizico2 on December 28, 2019, 11: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...
Title: Re: Spotify connect (librespot) on piCore
Post by: RomanoFX on January 05, 2020, 01:52:54 PM
On boot, I got the same issue. It only works when I launch it manually. Do you have an idea?
Title: Re: Spotify connect (librespot) on piCore
Post by: Rich on January 05, 2020, 02:44:25 PM
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.
Title: Re: Spotify connect (librespot) on piCore
Post by: RomanoFX on January 25, 2020, 08: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
Title: Re: Spotify connect (librespot) on piCore
Post by: RomanoFX on January 25, 2020, 08: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 &
Title: Re: Spotify connect (librespot) on piCore
Post by: RomanoFX on January 25, 2020, 03: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
Title: Re: Spotify connect (librespot) on piCore
Post by: Paul_123 on January 25, 2020, 10: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.
Title: Re: Spotify connect (librespot) on piCore
Post by: RomanoFX on January 26, 2020, 03: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
Title: Re: Spotify connect (librespot) on piCore
Post by: Paul_123 on January 26, 2020, 08:35:10 AM
It should use. /dev/hwrng
Title: Re: Spotify connect (librespot) on piCore
Post by: chemanork on July 02, 2020, 03: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?
Title: Re: Spotify connect (librespot) on piCore
Post by: chemanork on July 03, 2020, 06: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...
Title: Re: Spotify connect (librespot) on piCore
Post by: chemanork on July 07, 2020, 03: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: https://www.raspberrypi.org/forums/viewtopic.php?t=246431.

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
Title: Re: Spotify connect (librespot) on piCore
Post by: perceval on May 16, 2021, 12:54:17 PM
Hi Gerrelt,

I would like to compile librespot myself for my piCore :)
Could you provide us some indication on how to do so ? Did you encounter any problem during the building process ?

thank you very much,
 
Title: Re: Spotify connect (librespot) on piCore
Post by: Pueppchen on October 13, 2023, 02:52:14 PM
Thanks for sharing. Works as a charm
But I have a small problem with my alsa sink. I use a Rotel A12 amplifier and its USB input. The problem appears if the amplifier is turned off and so the destination device isn't present the whole librespot-prozess is killed with:

ALSA lib pcm_hw.c:1829:(_snd_pcm_hw_open) Invalid value for card
[2023-10-13T18:41:44Z ERROR librespot_playback::player] Audio Sink Error Connection Refused: <AlsaSink> Device hw:0,0 May be Invalid, Busy, or Already in Use, ALSA function 'snd_pcm_open' failed with error 'ENOENT: No such file or directory'

and I have to manually start the process again.

Here is my start line:
/mnt/mmcblk0p2/tce/librespot --name PiCoreWohnzimmer --cache /mnt/mmcblk0p2/tmp --bitrate 320 --backend alsa --format S24_3 --mixer softvol --volume-ctrl fixed --initial-volume 100 --device hw:0,0 > /dev/null 2>&1 &


So my question is if there is a way to "ignore" the Alsa error to keep the librespot process alive or do I have to start a watchdog which is starting the librespot process again when it's gone?

Sincerely, Ino
Title: Re: Spotify connect (librespot) on piCore
Post by: pjekachu on December 03, 2023, 03:52:59 AM
Hello!
I have installed librespot according to the opening post but something is not right:

Code: [Select]
cat /tmp/errors.txt
[2023-12-03T08:43:48Z INFO  librespot] librespot 0.5.0-dev d569d37 (Built on 2023-03-25, Build ID: V1V5A0fy, Profile: release)
[2023-12-03T08:43:49Z WARN  libmdns] Failed to register IPv6 receiver: Os { code: 97, kind: Uncategorized, message: "Address family not supported by protocol" }
[2023-12-03T08:44:20Z INFO  librespot_playback::mixer::softmixer] Mixing with softvol and volume control: Log(60.0)
[2023-12-03T08:44:20Z INFO  librespot_playback::convert] Converting with ditherer: tpdf
[2023-12-03T08:44:20Z INFO  librespot_playback::audio_backend::alsa] Using AlsaSink with format: S16
[2023-12-03T08:44:21Z INFO  librespot_core::session] Connecting to AP "ap-gew4.spotify.com:4070"
[2023-12-03T08:44:21Z INFO  librespot_core::session] Authenticated as "xxx" !
[2023-12-03T08:44:21Z INFO  librespot_core::session] Country: "IT"
[2023-12-03T08:44:21Z INFO  librespot_core::spclient] Resolved "gew4-spclient.spotify.com:443" as spclient access point
[2023-12-03T08:44:22Z INFO  librespot_playback::player] Loading <Watercooler> with Spotify URI <spotify:track:1CLHh77zFhvmgbOG27JyRR>
[2023-12-03T08:44:22Z ERROR librespot_playback::player] Unable to load encrypted file: Error { kind: FailedPrecondition, error: ParseIntError { kind: InvalidDigit } }

what am i missing? i reaaaally would like to finally use spotify on my various picoreplayers
Title: Re: Spotify connect (librespot) on piCore
Post by: Rich on December 03, 2023, 06:43:26 AM
Hi pjekachu
Welcome to the forum.

Hello!
I have installed librespot according to the opening post but something is not right:

Code: [Select]
cat /tmp/errors.txt
 ----- Snip -----

[2023-12-03T08:43:49Z WARN  libmdns] Failed to register IPv6 receiver: Os { code: 97, kind: Uncategorized, message: "Address family not supported by protocol" }

 ----- Snip -----
I would start by installing  ipv6-netfilter  for that error.