[GH-ISSUE #158] Huge latency when seeking/playing #110

Closed
opened 2026-02-27 19:28:53 +03:00 by kerem · 13 comments
Owner

Originally created by @bebehei on GitHub (Feb 19, 2018).
Original GitHub issue: https://github.com/librespot-org/librespot/issues/158

Hi guys,

I've built librespot successfully with pulseaudio support. It also works reasonably well.

I had been using Spotify Connect already for a long time with my Smartphone and computer together and in comparison to this, there is a small thing which bugs me.

Seeking and switching tracks makes the audio output stop for multiple seconds before the track starts or jumps to the seeked point.

The log reads the following:

[...]
INFO:librespot_playback::player: Track "Get Me To The Church On Time - Live At The Sands Hotel And Casino/1966" loaded
ERROR:librespot_playback::player: Could not write audio: Invalid argument
[...]
DEBUG:librespot_audio::fetch: File 5ce8e3b0c765502e75c3172090f1bb5e17e38fc9 complete, saving to cache
DEBUG:librespot_connect::spirc: kMessageTypePrev "butter" 4428af77be5ecd3a401356eec0e155b661993dec 8 0
DEBUG:librespot_playback::player: command=Seek(0)
ERROR:librespot_playback::player: Could not write audio: Invalid argument
[...]

There is no difference, if I change the bitrate/caching options.

Also interestingly, there is no delay, if I pause and play the track again.

Reproducible on ArchLinux on my desktop (amd64) and on an Odroid C2 (aarch64).

Originally created by @bebehei on GitHub (Feb 19, 2018). Original GitHub issue: https://github.com/librespot-org/librespot/issues/158 Hi guys, I've built librespot successfully with pulseaudio support. It also works reasonably well. I had been using Spotify Connect already for a long time with my Smartphone and computer together and in comparison to this, there is a small thing which bugs me. Seeking and switching tracks makes the audio output stop for multiple seconds before the track starts or jumps to the seeked point. The log reads the following: ``` [...] INFO:librespot_playback::player: Track "Get Me To The Church On Time - Live At The Sands Hotel And Casino/1966" loaded ERROR:librespot_playback::player: Could not write audio: Invalid argument [...] DEBUG:librespot_audio::fetch: File 5ce8e3b0c765502e75c3172090f1bb5e17e38fc9 complete, saving to cache DEBUG:librespot_connect::spirc: kMessageTypePrev "butter" 4428af77be5ecd3a401356eec0e155b661993dec 8 0 DEBUG:librespot_playback::player: command=Seek(0) ERROR:librespot_playback::player: Could not write audio: Invalid argument [...] ``` There is no difference, if I change the bitrate/caching options. Also interestingly, there is no delay, if I pause and play the track again. Reproducible on ArchLinux on my desktop (amd64) and on an Odroid C2 (aarch64).
kerem 2026-02-27 19:28:53 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@bebehei commented on GitHub (Feb 19, 2018):

Ok, I've got a workaround now. I'm using the pipe backend now and I'm piping everything into pacat. Now librespot works like a usual Spotify Connect and doesn't have these huge latencies, but I'd still favor a native working pulseaudio support.

See here for a the fully deployed workaround: https://bebehei.de/odroid-mediacenter/#librespot

<!-- gh-comment-id:366566638 --> @bebehei commented on GitHub (Feb 19, 2018): Ok, I've got a workaround now. I'm using the `pipe` backend now and I'm piping everything into `pacat`. Now librespot works like a usual Spotify Connect and doesn't have these huge latencies, but I'd still favor a native working pulseaudio support. See here for a the fully deployed workaround: https://bebehei.de/odroid-mediacenter/#librespot
Author
Owner

@lassos commented on GitHub (Mar 4, 2018):

Have the same problem. Using pulseaudio. Huge delay with seeking and switching forward or back

<!-- gh-comment-id:370208616 --> @lassos commented on GitHub (Mar 4, 2018): Have the same problem. Using pulseaudio. Huge delay with seeking and switching forward or back
Author
Owner

@lassos commented on GitHub (Mar 9, 2018):

I have no kodi. Just debian with pulseaudio. And in default.pa is nothing with keeper audio sinken alive. In original librespot i have never had seek play latency

<!-- gh-comment-id:371860455 --> @lassos commented on GitHub (Mar 9, 2018): I have no kodi. Just debian with pulseaudio. And in default.pa is nothing with keeper audio sinken alive. In original librespot i have never had seek play latency
Author
Owner

@bebehei commented on GitHub (Mar 9, 2018):

@lassos I don't have kodi either. Could you please elaborate?

<!-- gh-comment-id:371860791 --> @bebehei commented on GitHub (Mar 9, 2018): @lassos I don't have kodi either. Could you please elaborate?
Author
Owner

@lassos commented on GitHub (Mar 9, 2018):

https://github.com/librespot-org/librespot/issues/180

So in this thread the talk about

Try disabling option "keep audio sink alive" in Kodi

So where can i do it. In pulseaudio config ---system.pa

So what do you need.

And i noticed another thing. The loudness is much more less than in old librespot

<!-- gh-comment-id:371867049 --> @lassos commented on GitHub (Mar 9, 2018): https://github.com/librespot-org/librespot/issues/180 So in this thread the talk about Try disabling option "keep audio sink alive" in Kodi So where can i do it. In pulseaudio config ---system.pa So what do you need. And i noticed another thing. The loudness is much more less than in old librespot
Author
Owner

@ComlOnline commented on GitHub (Mar 10, 2018):

@lassos depending on how old your version of librespot was we implemented a change in the volume in #10 So that its no longer linear but logarithmic.

@bebehei I'll build a recent version with pulse audio and have a look tomorrow.

<!-- gh-comment-id:371991036 --> @ComlOnline commented on GitHub (Mar 10, 2018): @lassos depending on how old your version of librespot was we implemented a change in the volume in #10 So that its no longer linear but logarithmic. @bebehei I'll build a recent version with pulse audio and have a look tomorrow.
Author
Owner

@bebehei commented on GitHub (Mar 10, 2018):

@ComlOnline I'm regularly rebuilding librespot to match current master. I've even started using librespot after #10 had been merged.

<!-- gh-comment-id:372013207 --> @bebehei commented on GitHub (Mar 10, 2018): @ComlOnline I'm regularly rebuilding librespot to match current master. I've even started using librespot **after** #10 had been merged.
Author
Owner

@MarcelKr commented on GitHub (Mar 11, 2018):

@lassos @bebehei My issue wasn't related to Kodi. I was not a member of the audio groupd and therefore I had no sound. Now that I fixed that, I get the exact symptoms seen in this issue. E.g. playback working but with the Could not write audo error message and the delay when seeking.

<!-- gh-comment-id:372122467 --> @MarcelKr commented on GitHub (Mar 11, 2018): @lassos @bebehei My issue wasn't related to Kodi. I was not a member of the ``audio`` groupd and therefore I had no sound. Now that I fixed that, I get the exact symptoms seen in this issue. E.g. playback working but with the ``Could not write audo`` error message and the delay when seeking.
Author
Owner

@lassos commented on GitHub (Mar 12, 2018):

Oh , OK. I am getting the same error -> Could not write audio

mpd@-XXX:/var/logRUST_BACKTRACE=1 /usr/bin/librespot --username XXX --password XXX --bitrate 320 --name XXX --backend pulseaudio INFO:librespot: librespot 593dfa0 (2018-02-27). Built on 2018-02-28. Build ID: heiwVZ8W INFO:librespot_core::session: Connecting to AP "gew1-accesspoint-b-pnns.ap.spotify.com:4070" INFO:librespot_core::session: Authenticated as "XXX" ! INFO:librespot_core::session: Country: "DE" INFO:librespot_playback::player: Loading track "Norrsken" INFO:librespot_playback::player: Track "Norrsken" loaded ERROR:librespot_playback::player: Could not write audio: Invalid argument ^[[A ERROR:librespot_playback::player: Could not write audio: Invalid argument

it would be great to get a solution cause it's really uncomftable to wait few seconds to seek or play next titles. thanks lars

<!-- gh-comment-id:372341765 --> @lassos commented on GitHub (Mar 12, 2018): Oh , OK. I am getting the same error -> Could not write audio `mpd@-XXX:/var/logRUST_BACKTRACE=1 /usr/bin/librespot --username XXX --password XXX --bitrate 320 --name XXX --backend pulseaudio INFO:librespot: librespot 593dfa0 (2018-02-27). Built on 2018-02-28. Build ID: heiwVZ8W INFO:librespot_core::session: Connecting to AP "gew1-accesspoint-b-pnns.ap.spotify.com:4070" INFO:librespot_core::session: Authenticated as "XXX" ! INFO:librespot_core::session: Country: "DE" INFO:librespot_playback::player: Loading track "Norrsken" INFO:librespot_playback::player: Track "Norrsken" loaded ERROR:librespot_playback::player: Could not write audio: Invalid argument ^[[A ERROR:librespot_playback::player: Could not write audio: Invalid argument` it would be great to get a solution cause it's really uncomftable to wait few seconds to seek or play next titles. thanks lars
Author
Owner

@bebehei commented on GitHub (Mar 12, 2018):

Like I said it: Use librespot --backend pipe | pacat as a workaround. This helps and lets the issue go away. It doesn't change the fact, that librespot's pulseaudio support is broken, but it works ™️

If you need a full writeup, you can find it on my webpage.

<!-- gh-comment-id:372347289 --> @bebehei commented on GitHub (Mar 12, 2018): Like I said it: Use `librespot --backend pipe | pacat` as a workaround. This helps and lets the issue go away. It doesn't change the fact, that librespot's pulseaudio support is broken, but it works :tm: If you need a full writeup, [you can find it on my webpage](https://bebehei.de/odroid-mediacenter/#librespot).
Author
Owner

@lassos commented on GitHub (Mar 12, 2018):

pretty cool, i have overlooked it, i am sorry. worked for me .-)

thanks a lot bebehei

<!-- gh-comment-id:372349022 --> @lassos commented on GitHub (Mar 12, 2018): pretty cool, i have overlooked it, i am sorry. worked for me .-) thanks a lot bebehei
Author
Owner

@sashahilton00 commented on GitHub (Mar 20, 2018):

This is somewhat present on portaudio. What I believe the problem is, is that Track.load is called whenever a song is selected, even if only briefly when skipping through them. Hence, if you skip 5 songs, librespot loads 5 songs before the one you actually want. The solution is to implement an audio_queue, which will hopefully happen at some point. This leads to the loading latency. With regards to the seeking, that sounds like a CPU limitation, given that the pipe works.

<!-- gh-comment-id:374654954 --> @sashahilton00 commented on GitHub (Mar 20, 2018): This is somewhat present on portaudio. What I believe the problem is, is that Track.load is called whenever a song is selected, even if only briefly when skipping through them. Hence, if you skip 5 songs, librespot loads 5 songs before the one you actually want. The solution is to implement an audio_queue, which will hopefully happen at some point. This leads to the loading latency. With regards to the seeking, that sounds like a CPU limitation, given that the pipe works.
Author
Owner

@bebehei commented on GitHub (Jun 2, 2018):

I found out, that @brain0 fixed this in meantime with PR #194. Update to current master to have the changes included.

ping @Obrekr, you may want to update your commits again.

<!-- gh-comment-id:394113165 --> @bebehei commented on GitHub (Jun 2, 2018): I found out, that @brain0 fixed this in meantime with PR #194. Update to current master to have the changes included. ping @Obrekr, you may want to update your commits again.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/librespot#110
No description provided.