Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track skipping due to upstream Spotify API issues. #669

Open
brettmillerb opened this issue Sep 4, 2024 · 23 comments
Open

Track skipping due to upstream Spotify API issues. #669

brettmillerb opened this issue Sep 4, 2024 · 23 comments
Labels
bug Something isn't working

Comments

@brettmillerb
Copy link

Describe the problem
When connecting to Balena raspberryPi device the tracks skip continuously.

To Reproduce
Open Spotify and attempt to connect to Balena Airplay device.
Tracks just begin skipping, some tracks play but the majority do not.

Expected behavior
Track selected plays on Balena device

Screenshots

 spotify  [2024-09-04T11:50:44Z ERROR librespot_core::channel] channel error: 2 0
 spotify  [2024-09-04T11:50:44Z ERROR librespot_playback::player] Unable to load encrypted file: ChannelError
 spotify  [2024-09-04T11:50:44Z WARN  librespot_playback::player] Skipping to next track, unable to load track <SpotifyId { id: 11583470944873040899923648362564505491, audio_type: Track }>: ()
 spotify  [2024-09-04T11:50:44Z INFO  librespot_playback::player] Loading <Apéro Spritz> with Spotify URI <spotify:track:4K9CUUcvjacTnHdnAnzGRP>

Additional Errors:

 spotify  [2024-09-04T11:54:01Z ERROR librespot_playback::player] Unable to load encrypted file: ChannelError
 spotify  [2024-09-04T11:54:01Z WARN  librespot_playback::player] Skipping to next track, unable to load track <SpotifyId { id: 297718726312721626386930062394132188552, audio_type: Track }>: ()

Device information

  • Board (hardware info): Raspberry Pi 3
  • Device type (as seen in balenaCloud): Raspberry Pi 3
  • balenaOS version: balenaOS 5.1.20+rev1

Additional context
Seems a Spotify API change is the cause and recommendation is to build librespot from dev branch which does not have the issue.

librespot-org/librespot#1322

@brettmillerb brettmillerb added the bug Something isn't working label Sep 4, 2024
@mivittek
Copy link

mivittek commented Sep 4, 2024

I can see in
/plugins/spotify/Dockerfile.template

we are using image
FROM andrewn/librespot:0.4.2-pulseaudio

@andrewn is it possible for you to rereate docker image of librespot from dev branch ?

@brettmillerb
Copy link
Author

I opened andrewn/librespot-docker#2 which I think should allow a new image to be created from dev branch but I don't know how to validate.

@brettmillerb
Copy link
Author

Because I am a masochist who doesn't know when to quite whilst he's ahead and I already possess a docker hub account I thought I'd try building the image myself and ran into a few issues:

Modified build-pulseaudio.sh

# not sure if this should align with the dev branch build but it was unique so 🤷 
# version = "0.5.0-dev" is dev branch version in cargo.toml
LIBRESPOT_VERSION="0.4.2-dev"
DOCKER_NAMESPACE="brettmillerit"

exec:
bash build-pulseaudio.sh

=> WARN: FromAsCasing: 'as' and 'FROM' keywords' casing do not match (line 4)                                                      0.1s
 => ERROR [internal] load metadata for docker.io/balenalib/rpi-alpine:edge                                                          0.9s
 => CANCELED [internal] load metadata for docker.io/balenalib/rpi-alpine:3.14-run 

ERROR: failed to solve: balenalib/rpi-alpine:edge: failed to resolve source metadata for docker.io/balenalib/rpi-alpine:edge: error getting credentials - err: exit status 255, out: ``

I then tried rebuilding using :3.14 and received a cargo error (I don't remember why I thought changing from edge would work:

> [librespot-builder 6/6] RUN cargo build   --release   --features alsa-backend,pulseaudio-backend   --verbose:
0.997 error: failed to parse manifest at `/app/librespot-src/Cargo.toml`
0.998 
0.998 Caused by:
0.999   feature `edition2021` is required
0.999 
0.999   this Cargo does not support nightly features, but if you
0.999   switch to nightly channel you can add
0.999   `cargo-features = ["edition2021"]` to enable this feature
------
Dockerfile.pulseaudio.template:20
--------------------
  19 |     
  20 | >>> RUN cargo build \
  21 | >>>   --release \
  22 | >>>   --features alsa-backend,pulseaudio-backend \
  23 | >>>   --verbose
  24 |     
--------------------
ERROR: failed to solve: process "/bin/sh -c cargo build   --release   --features alsa-backend,pulseaudio-backend   --verbose" did not complete successfully: exit code: 101

I moved back to edge and I think I have it building....or it's stuck building and going to throw an error eventually 🤷

@brettmillerb
Copy link
Author

So I spent more time than I care to admit figuring this out.

Was able to get the docker image built using @andrewn repo, pushed to my own docker hub repo for testing. Or at least I was able to get 2/4 images built.

I was using docker in docker on my Windows machine to do this so not sure why it took so long but left it over night and it still hadn't finished the remaining two images.

Switched out my BalenaSound project to use the image from my docker hub repo:
https://github.com/brettmillerb/balena-sound-hole/blob/main/plugins/spotify/Dockerfile.template

Built a docker container for that project so I could install Balena CLI as I have no admin rights on this windows machine 🤦

Confirmed a push was using the correct image:

[airplay]           Step 1/10 : FROM mikebrady/shairport-sync:4.1.1 as shairport
[unbound]           Step 1/4 : FROM klutchell/unbound:v1.19.1@sha256:125cd0c03ea2e5386aec2d9e162de00d6c59b20ee2adf4529818ee025b59e79d
[sound-supervisor]   ---> 1b4441c7cf2c
[sound-supervisor]  Step 2/15 : WORKDIR /usr/src
[spotify]           Step 1/4 : FROM brettmillerit/librespot:0.4.2-dev-pulseaudio-rpi
[sound-supervisor]   ---> Running in f021eb48c5d9
[sound-supervisor]  Removing intermediate container f021eb48c5d9

Was able to connect from Spotify without skipping tracks.
image

@brettmillerb
Copy link
Author

Went back to check the original issue and seems Spotify have reverted their API version changes

librespot-org/librespot#1322 (comment)

However, when Spotify decide to make those changes Balena will need to utilise the new 0.5.0 and the container images will need to be rebuilt and updated.

Guess I learned a tonne about the project 🤣

@brettmillerb
Copy link
Author

Also looks like they're pushing for a 0.5.0 release:

librespot-org/librespot#1279 (comment)

@andrewn
Copy link
Contributor

andrewn commented Sep 14, 2024

Hi @brettmillerb, sorry for the delay. I can try and do a new build of the repo in the next couple of days.

I guess 0.5.0 is backwards compatible with the old API too?

How should I test it?

@brettmillerb
Copy link
Author

Hi @andrewn

I guess 0.5.0 is backwards compatible with the old API too?
Spotify rolled back the changes and I am still using the dev branch build I generated.

I am way past the realms of my existing knowledge as it is. I have noticed with the dev branch build that there are random disconnects when selecting my raspi from Spotify.

May be worth hanging fire for an official release of 0.5.0 before rebuilding the docker images since Spotify rolled back the changes their end 🤷‍♂️

@mivittek
Copy link

Hi there, currently, i am again getting a lot of:

librespot_core::session] Connection reset by peer (os error 104)
librespot_connect::spirc] subscription terminated

As suggested in docs, there is no actual solution, only to upgrade.
balena-sound-spotify-connect-os-error-104

There is already new librespot release v0.5.0 avalible.

i forked balenasound and updated tag for docker image
https://github.com/mivittek/balena-sound/blob/master/plugins/spotify/Dockerfile.template

and also andrewn librespot, where i bumed tag versions to 0.5.0
https://github.com/mivittek/librespot-docker

Bui i am unable to build docker image with github actions, there is some weird cargo build error.
https://github.com/mivittek/librespot-docker/actions/runs/11425163023/job/31786487840

@andrewn
Copy link
Contributor

andrewn commented Oct 26, 2024

It took a bit of fiddling around, but I have a version that seems to build v0.5.0 here: andrewn/librespot-docker#3

The GitHub actions have never worked, so I'm building them manually on my laptop.

The only thing is that I don't use balena-sound anymore so once they're up, someone's going to need to run them on a Pi to make sure they work.

I'll post here once they're on dockerhub.

@mivittek
Copy link

Cool, i have pi4 and pi3 at my disposal, so i can try to build it on device :)

@wheredidthecostgo
Copy link
Contributor

It took a bit of fiddling around, but I have a version that seems to build v0.5.0 here: andrewn/librespot-docker#3

The GitHub actions have never worked, so I'm building them manually on my laptop.

The only thing is that I don't use balena-sound anymore so once they're up, someone's going to need to run them on a Pi to make sure they work.

I'll post here once they're on dockerhub.

I can give it a go on a pi2

@andrewn
Copy link
Contributor

andrewn commented Oct 26, 2024

I left my laptop cross-compiling all the binaries and went out for the day.

I meant it would be great to check the compiled binaries work with balena-sound once they’re uploaded to docker.

@andrewn
Copy link
Contributor

andrewn commented Oct 27, 2024

@mivittek @wheredidthecostgo The new v0.5.0 images are now published to docker hub as andrewn/librespot.

Please test them out and let me know how they work for you

@mivittek
Copy link

mivittek commented Oct 27, 2024

Well, i managed to build it and pull form docker repo, thanks for that. But there is error while running build. Some manifest missing ?

[airplay]           Step 1/10 : FROM mikebrady/shairport-sync:4.1.1 as shairport
[spotify]           Step 1/4 : FROM andrewn/librespot:0.5.0-pulseaudio
[spotify]           manifest for andrewn/librespot:0.5.0-pulseaudio not found: manifest unknown: manifest unknown

---- i manually deleted some of build data

[Error]             Some services failed to build:
[Error]               Service: spotify
[Error]                 Error: manifest for andrewn/librespot:0.5.0-pulseaudio not found: manifest unknown: manifest unknown
[Info]              Built on df9c640
[Error]             Not deploying release.

i tried to debug it, but for main packge - without platform there is no manifest

docker manifest inspect andrewn/librespot:0.5.0-pulseaudio      
no such manifest: docker.io/andrewn/librespot:0.5.0-pulseaudio

When i edit it manually as you cen see it in commit, it works like a charm.
/mivittek/balena-sound/commit/1847d9f974714fd421f168e48bace59701ccfd92

@andrewn
Copy link
Contributor

andrewn commented Oct 27, 2024

@mivittek Thanks for reporting that!

I forgot to enable the "create manifest" line in the script. 🤦

If you try again it should work.

@wheredidthecostgo
Copy link
Contributor

@mivittek @wheredidthecostgo The new v0.5.0 images are now published to docker hub as andrewn/librespot.

Please test them out and let me know how they work for you

I've built and deployed! I'll test and see if it corrects the (os error 104)

@mivittek
Copy link

mivittek commented Oct 27, 2024

I redeployed image and since commit/f954c98 I am running 4+ hours and no error yet, so I got high hopes :)

Anyway, this runs at my home eveyday, so i'll get back in few days. Thanks @andrewn 🥇

@wheredidthecostgo
Copy link
Contributor

@andrewn It has worked perfect for me all day! Thank you!!!

@mivittek
Copy link

mivittek commented Nov 1, 2024

Its still working like a charm, should we create PR with update + bumped release version ?

@wheredidthecostgo
Copy link
Contributor

It worked fine for a while, now I'm getting status code 502 errors. See below. I'm guessing it is some type of bad gateway error, but not sure why it would be happening.

But os 104 errors are gone, so I'm not sure what to do.

502

@mivittek
Copy link

mivittek commented Nov 2, 2024

Hi there !
Error 502 happens after starting playing after some time without playback. It happens for me as well, but it does not

Log:

Supervisor starting
 spotify  [2024-11-02T17:13:30Z ERROR librespot_connect::spirc] ContextError: Error { kind: Unknown, error: StatusCode(502) }

This issue is documented in librespot , without any real solution :(
Comments in this tread are saying that session handling has been improved and there is new librespot version, 0.6.0

reference:
librespot-org/librespot#609

@wheredidthecostgo
Copy link
Contributor

Thanks!

Hi there !
Error 502 happens after starting playing after some time without playback. It happens for me as well, but it does not

Log:

Supervisor starting
 spotify  [2024-11-02T17:13:30Z ERROR librespot_connect::spirc] ContextError: Error { kind: Unknown, error: StatusCode(502) }

This issue is documented in librespot , without any real solution :(
Comments in this tread are saying that session handling has been improved and there is new librespot version, 0.6.0

reference:
librespot-org/librespot#609

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants