plietar / librespot

Open Source Spotify client library
MIT License
1.14k stars 185 forks source link

Tracks skip after a few seconds of playing #231

Closed Dantoes closed 7 years ago

Dantoes commented 7 years ago

I have an issue with librespot on my RPI2 where every tracks only plays for about 10-40 seconds. Then the playback abruptly stops and the next track is played (again only a few seconds).

Console ouput:

pi@musicbox:~ $ RUST_BACKTRACE=1 /home/pi/librespot/librespot --username some.username --name 'MusicBox' 2>&1 > /tmp/test
INFO:librespot: librespot 910974e (2017-07-17). Built on 2017-07-23. Build ID: vL9wym2D
Password for some.username:
WARN:mdns::fsm: error sending packet Error { repr: Os { code: 99, message: "Cannot assign requested address" } }
INFO:librespot::session: Connecting to AP "gew1-accesspoint-b-9kxv.ap.spotify.com:4070"
INFO:librespot::session: Authenticated as "some.username" !
INFO:librespot::session: Country: "DE"
INFO:librespot::player: Loading track "It Takes A Lot To Know A Man"
INFO:librespot::player: Track "It Takes A Lot To Know A Man" loaded
INFO:librespot::player: Loading track "Mad World (Feat. Michael Andrews)"
INFO:librespot::player: Track "Mad World (Feat. Michael Andrews)" loaded
^Cpi@musicbox:~ $

Please note the error sending packet Error, which does not appear when running librespot on my PC.

On stderr lots of binary data is written which is why I redirected the output. After less than one minute the file got 107 MB big. Here's what it looks like (shortened, output varies for each tests):

<F7>^D<C7>      +^D-    6^CG^B<A6>^G@^A<CC>^F"^@<CA>^EESC<FF><C0>^D^R<FE><A1>^C<F6><FC>t^B<ED><FB>^^A<F6><FA>M^@^C<FA>3<FF>!<F9>0<FE>[<F8>=<FD><B5><F7>L<FC>(<F7>l
<FB><AB><F6><95><FA>Y<F6><C7><F9>6<F6>^P<F9>"<F6>c<F8>^]<F6><C2><F7>^_<F6>$<F7>^X<F6>y<F6>^T<F6><D7><F5>^O<F6>?<F5><F8><F5><99><F4><DF><F5><ED><F3><CD><F5>><F3>
<BF><F5><85><F2><B3><F5><CE><F1><A4><F5>^T<F1><AB><F5>b<F0><CF><F5><C0><EF><EF><F5>^\<EF>^N<F6><87><EE>5<F6>^R<EE>T<F6><A1><ED><80><F6>6<ED><C9><F6><E3><EC>!<F7>
<AA><EC><95><F7><8B><EC>^V<F8>r<EC>|<F8>h<EC><CE><F8><86><EC>^\<F9><C1><EC>e<F9>^K<ED><98><F9>m<ED><AA><F9><D6><ED><B2><F9>I<EE><C4><F9><D0><EE><D4><F9>m<EF><CD>
<F9>^Z<F0><A7><F9><BC><F0><8B><F9>F<F1><87><F9><D1><F1>z<F9>W<F2>`<F9><C3><F2>I<F9>^^<F3>'<F9>d<F3><F3><F8><88><F3><BD><F8><91><F3><83><F8><83><F3>/<F8>]<F3><CD>
<F7>$<F3><8D><F7><E7><F2>k<F7><BD><F2>F<F7><A7><F2>!<F7><A0><F2><F2><F6><A3><F2><B9><F6><B4><F2><96><F6><DF><F2>y<F6>)<F3>M<F6><8B><F3>+<F6>^A<F4>^U<F6><86><F4>
<FD><F5>$<F5><FE><F5><EB><F5>1<F6><D3><F6>x<F6><CD><F7><C3><F6><E1><F8>#<F7>^D<FA><97><F7>&<FB>^P<F8>I<FC><8B><F8>o<FD>^V<F9><95><FE><BC><F9><BE><FF>q<FA><E0>^@,
<FB><F9>^A<EB><FB>^T^C<AC><FC>.^Du<FD>B^EL<FE>T^F'<FF>Y^G<F8><FF><BC>^@*  x^A<EA> #^B<87>
<B7>^B^B^K?^CR^K<AF>^C<81>^K<FB>^C<96>^K^\^D<87>^K^X^DT^K^X^D^N^K^P^D<AA>
<E8>^C'
<CD>^C<9B>      <B1>^C<FF>^Hp^C<^C<A0>^G^W^C<F0>^F<E3>^BB^F<C5>^B<AC>^E<B1>^B^]^E<99>^B<8E>^D<9A>^B^S^D<95>^B<A0>^C<86>^B0^C<8D>^B<D0>^B<8B>^Bo^Bi^B^F^B7^B<99>^A
<F4>^A$^A<A0>^A<A9>^@5^A&^@<B6>^@<9B><FF>4^@^V<FF><A0><FF><88><FE><FD><FE><E8><FD>r<FE>H<FD><E7><FD><9A><FC>C<FD><DD><FB><9F><FC>'<FB><EA><FB>n<FA>ESC<FB><A4><F9>F<FA><D9><F8>c<F9>^T<F8>~<F8>T<F7><A3><F7><9F><F6><B9><F6><F6><F5><D2><F5>g<F5>^B<F5><F4><F4>,<F4><8A><F4>d<F3>4<F4><B8><F2><FD><F3>^N<F2><DA><F3>v<F1><C9><F3><F8>
<F0><C8><F3><92><F0><CF><F3>L<F0><F0><F3>^N<F0>&<F4><E1><EF>[<F4><ED><EF><98><F4>^S<F0><D4><F4>?<F0>^D<F5><82><F0>7<F5><CB><F0>_<F5>ESC<F1>m<F5>|<F1>u<F5><D0><F1>q<F5>^U<F2>[<F5>O<F2>:<F5>c<F2><FB><F4>c<F2><AE><F4>W<F2>h<F4>^_<F2>^O<F4><CD><F1><A3><F3>m<F1>.<F3><EA><F0><9D><F2>`<F0><F7><F1><CC><EF>?<F1>^M<EF>o<F0>E<EE><AA>
<EF><81><ED><F2><EE><AD><EC>4<EE><DD><EB><83><ED>^\<EB><DA><EC>u<EA>?<EC><EE><E9><C7><EB>l<E9>[<EB>^D<E9><F7><EA><D7><E8><B3><EA><BC><E8><80><EA><AD><E8>a<EA><C1>
<E8>`<EA><EA><E8>f<EA>^]<E9><81><EA>T<E9><B8><EA><93><E9><F9><EA><EB><E9>V<EB><<EA><C9><EB>q<EA>9<EC><AF><EA><C5><EC><F7><EA>l<ED>+<EB>^M<EE>X<EB><B5><EE><90><EB>a<EF><D3><EB><FD><EF>^]<EC><94><F0>w<EC>-<F1><F0><EC><BE><F1><85><ED>I<F2>9<EE><CD><F2>^V<EF>F<F3>^Z<F0><C0><F3>5<F1>N<F4>Z<F2><E4><F4><94><F3>v<F5><F5><F4>^_<F6>_
<F6><DF><F6><B1><F7><A8><F7>^M<F9><94><F8>t<FA><98><F9><B3><FB><9A><FA><D9><FC><AF><FB>^H<FE><D7><FC>0<FF><FA><FD>L^@!<FF>Y^AW^@K^B<8B>^A<^C<B4>^B:^D<D9>^C/^E<ED>
^D(^F<E8>^E6^G<D6>^F<A3>^G<  @
<E1>^H7^Kd      ^^^L<D2>        ^A^MC
<CA>^M<A8>

I can only assume, but it looks like the decoded audio data is written to stderr.

OS: Raspbian on RPI2 Version: 910974e Cross-compiled using the provided docker image.

plietar commented 7 years ago

That looks like librespot is using the stdout backend, which is odd. Do you hear any audio during those few seconds ?

Can you run librespot --name 'MusicBox' --backend '?' ?

Dantoes commented 7 years ago

There's wasn't any audio output before the tracks stopped. Here's your requested output:

pi@musicbox:~ $ RUST_BACKTRACE=1 /home/pi/librespot/librespot --name 'MusicBox' --backend '?'
INFO:librespot: librespot 910974e (2017-07-17). Built on 2017-07-23. Build ID: vL9wym2D
Available Backends :
- pipe (default)
pi@musicbox:~ $

Looks like stdout is the only output available which would explain the behaviour. I ran speaker-test and aplay which both worked fine. So the audio device is available and works.

Is this an issue of detecting the audio device or has it something to do with the compilation?

plietar commented 7 years ago

Your librespot binary was built without any backends enabled. What command did you use to build it ?

mherger commented 7 years ago

I'd say this is a dupe of issue #175

Dantoes commented 7 years ago

I built it on my PC (Mint 18.2) using these commands:

  409  docker build -t librespot-cross -f contrib/Dockerfile .
  410  docker run -v /tmp/librespot-build:/build librespot-cross cargo build --release --target arm-unknown-linux-gnueabihf --no-default-features --features alsa

My PC also has a working sound card if it plays any role in the compile process.

Dantoes commented 7 years ago

Comparing the commands with the ones in the Readme, I noticed it I have used --features alsa instead of --features alsa-backend. I copied & pasted the commands and probably missed the last bit. I guess that is the cause of my issue. I'll try to recompile librespot with the correct parameters and answer back if it fixed the issue.

michaelherger commented 7 years ago

As I said: this is a dupe of issue #175 . Something in the overall system is confusing "all data sent" with "all data played". As soon as all data has been received the player class receives a kMessageTypeNext, telling it to start playback of the next track. As the pipe backend would download the file at full speed, this only takes seconds. With other backends the end can be truncated. See issue #175 .

Dantoes commented 7 years ago

After recompiling with the correct parameter everything works flawlessly again. The audio is back, the console output is gone (obviously) and the tracks do not skip anymore. I don't know if it has something to do with #175 as @michaelherger stated. I leave that to you guys to decide.

Anyway, thanks @plietar for pointing me in the right direction.