devgianlu / go-librespot

Yet another open source Spotify client, written in Go.
GNU General Public License v3.0
44 stars 7 forks source link

Gapless playback with Crossfade #31

Open tylkie opened 2 months ago

tylkie commented 2 months ago

Your java version had a crossfade option along with internal prefetching for gapless playback. Currently, if my senses do not trick me, the first chunk gets loaded on demand, while the rest of the chunks of the same song get prefetched. With a very bad internet connection this sometimes results in gaps between songs.

When looking at the log, one can see that the player currently even emits a "not_playing" event between songs.

Apr 18 08:50:24 mysterion librespot-go[470966]: time="2024-04-18T08:50:24+02:00" level=debug msg="selected format OGG_VORBIS_160 for spotify:track:6FKU84JHM1lbiy5Dx0Dyqd" Apr 18 08:50:24 mysterion librespot-go[470966]: time="2024-04-18T08:50:24+02:00" level=debug msg="requested aes key for file 4edb75d47086de2a3d55b067cd8e3d00cc2e1a9e, gid: 6FKU84JHM1lbiy5Dx0Dyqd" Apr 18 08:50:25 mysterion librespot-go[470966]: time="2024-04-18T08:50:25+02:00" level=debug msg="fetched first chunk of 8, total size is 4127448 bytes" Apr 18 08:50:25 mysterion librespot-go[470966]: time="2024-04-18T08:50:25+02:00" level=trace msg="seek to 0ms (diff: -198ms, samples: 0, bytes: 0)" Apr 18 08:50:25 mysterion librespot-go[470966]: time="2024-04-18T08:50:25+02:00" level=info msg="loaded track \"The Joker\" (uri: spotify:track:6FKU84JHM1lbiy5Dx0Dyqd, paused: false, position: 0ms, duration: 217800ms)" Apr 18 08:50:25 mysterion librespot-go[470966]: time="2024-04-18T08:50:25+02:00" level=debug msg="vorbis: corrupt or missing data in bitstream" Apr 18 08:50:25 mysterion librespot-go[470966]: time="2024-04-18T08:50:25+02:00" level=debug msg="put connect state because PLAYER_STATE_CHANGED" Apr 18 08:50:25 mysterion librespot-go[470966]: time="2024-04-18T08:50:25+02:00" level=trace msg="emitting websocket event: metadata" Apr 18 08:50:25 mysterion librespot-go[470966]: time="2024-04-18T08:50:25+02:00" level=debug msg="put connect state because PLAYER_STATE_CHANGED" Apr 18 08:50:25 mysterion librespot-go[470966]: time="2024-04-18T08:50:25+02:00" level=trace msg="emitting websocket event: playing" Apr 18 08:50:26 mysterion librespot-go[470966]: time="2024-04-18T08:50:26+02:00" level=debug msg="fetched chunk 1/7, size: 524288" Apr 18 08:50:26 mysterion librespot-go[470966]: time="2024-04-18T08:50:26+02:00" level=debug msg="fetched chunk 2/7, size: 524288" Apr 18 08:50:27 mysterion librespot-go[470966]: time="2024-04-18T08:50:27+02:00" level=debug msg="fetched chunk 3/7, size: 524288" Apr 18 08:50:42 mysterion librespot-go[470966]: time="2024-04-18T08:50:42+02:00" level=debug msg="fetched chunk 4/7, size: 524288" Apr 18 08:51:09 mysterion librespot-go[470966]: time="2024-04-18T08:51:09+02:00" level=debug msg="fetched chunk 5/7, size: 524288" Apr 18 08:51:37 mysterion librespot-go[470966]: time="2024-04-18T08:51:37+02:00" level=debug msg="fetched chunk 6/7, size: 524288" Apr 18 08:52:05 mysterion librespot-go[470966]: time="2024-04-18T08:52:05+02:00" level=debug msg="fetched chunk 7/7, size: 457432" Apr 18 08:54:01 mysterion librespot-go[470966]: time="2024-04-18T08:54:01+02:00" level=trace msg="emitting websocket event: not_playing" Apr 18 08:54:01 mysterion librespot-go[470966]: time="2024-04-18T08:54:01+02:00" level=debug msg="loading track spotify:track:0NIRG3SEn2Zf88o3qHJil5 (paused: false, position: 0ms)" Apr 18 08:54:01 mysterion librespot-go[470966]: time="2024-04-18T08:54:01+02:00" level=debug msg="put connect state because PLAYER_STATE_CHANGED" Apr 18 08:54:01 mysterion librespot-go[470966]: time="2024-04-18T08:54:01+02:00" level=trace msg="emitting websocket event: will_play" Apr 18 08:54:02 mysterion librespot-go[470966]: time="2024-04-18T08:54:02+02:00" level=debug msg="selected format OGG_VORBIS_160 for spotify:track:0NIRG3SEn2Zf88o3qHJil5" Apr 18 08:54:02 mysterion librespot-go[470966]: time="2024-04-18T08:54:02+02:00" level=debug msg="requested aes key for file 4569298b745f1ef6d32a3ae636537bab5ae7509a, gid: 0NIRG3SEn2Zf88o3qHJil5"

devgianlu commented 1 month ago

@tylkie I have started implemented some prefetching with the latest commits if you're interested in trying it out.

tylkie commented 1 month ago

Not just interested... I am excited to try it out. Just merged the commits along with the player and stream commits. Works smoothly so far. Gonna let it run for a couple of days.

tylkie commented 1 month ago

After four days of continuous usage, I conclude that prefetching works flawlessly for me.

devgianlu commented 1 month ago

Nice! Which commit are you using exactly?

tylkie commented 1 month ago

I used the latest release source files (0.0.15) and merged the diff files from 75ef7eb and 51a1509 manually. From your question I deduced that I have missed some commits in between. And indeed I missed 2a52394. My bad. I now downloaded the entire repository up to 5385999. Thank you for the hint. This is like endless Christmas... unpacking the same goodie over and over :-D

devgianlu commented 1 month ago

Yeah I mentioned because I had some "temporary" commits in there that weren't quite ready, as of now master includes all gapless changes.