music-assistant / hass-music-assistant

Turn your Home Assistant instance into a jukebox, hassle free streaming of your favorite media to Home Assistant media players.
Apache License 2.0
1.21k stars 44 forks source link

Music / playing info out of sync using external snapcast & spotify #2402

Open chatziko opened 1 month ago

chatziko commented 1 month ago

What version of Music Assistant has the issue?

2.0.4

What version of the Home Assistant Integration have you got installed?

2024.5.1

Have you tried everything in the Troubleshooting FAQ and reviewed the Open and Closed Issues and Discussions to resolve this yourself?

The problem

I'm experiencing a weird issue in which the music being played becomes out of sync with the currenly playing info displayed in MA. What is strange is that it happens only with Snapcast / Spotify combination, and only when using an external snapserver.

It starts at various moments, but finally I found a simple way to reproduce it with 100% success rate (at least in my setup).

How to reproduce

Music Providers

Player Providers

Full log output

log.txt

Additional information

No response

What version of Home Assistant Core are your running

2024.5.5

What type of installation are you running?

Home Assistant OS

On what type of hardware are you running?

Generic x86-64 (e.g. Intel NUC)

SantiagoSotoC commented 2 weeks ago

Try to use the ip of the snapserver and not a hostname as this has been a problem in the past

chatziko commented 2 weeks ago

Thanks for the tip, it doesn't seem to make a difference.

On the other hand, although in previous tests I could reproduce the problem with 100% success rate, with MA 2.0.6 it seems to happen only with certain spotify albums, but not others. Pretty strange...

OzGav commented 2 weeks ago

Have you tried any other music providers?

chatziko commented 2 weeks ago

Just the filesystem provider, no problem with that.

OzGav commented 2 weeks ago

Ok will try and replicate this

chatziko commented 2 weeks ago

Just the filesystem provider, no problem with that.

Actually I take this back. I had tried it several times, I'm sure, but now I tried it a few more and I managed to reproduce the issue with the filesystem provider (which will likely make it easier to spot the issue). It doesn't happen with all songs, but it does happen.

chatziko commented 2 weeks ago

Some more info: I did several tests with the same filesystem album. Only 2 out of the 8 songs reproduce the problem, and the behaviour of each song is always the same, either it always works, or it always reproduces the problem.

Moreover, as with my initial experiments, the issue only appears with an external snapserver (configured with either IP or hostname). With the internal snapserver the problem never appears.

SantiagoSotoC commented 2 weeks ago

It's so weird because we don't treat the embedded different than the external, I will try to reduce the amount of times that stream is created, maybe that will help. @chatziko can you test some things in the dev addon ?

chatziko commented 2 weeks ago

Sure, I could maybe setup a local dev environment and try it there. Let me know what you want me to test.

SantiagoSotoC commented 2 weeks ago

When I have the changes I will let you know here, thanks

SantiagoSotoC commented 5 days ago

@chatziko Did you notice that it happens more with v0.28 than with v0.27 ? Because for the next beta we are going to use v0.28 because the debian repo was updated, and I noticed that it happens a lot.

chatziko commented 5 days ago

I tried both just to see whether it's specific to one version, but I'm mostly using v0.28 so I can't compare the frequency between the versions.

SantiagoSotoC commented 2 days ago

Off topic question but since you are using version 28 did you notice that the streams are not removed from snapcast ?

chatziko commented 2 days ago

Not sure whether this is what you mean, but I just opened snapweb and I see two old streams there (MA has been idle since yesterday), see below. First time I see this, but I rarely open snapweb, so maybe I didn't notice it.

image

SantiagoSotoC commented 2 days ago

Yes, that's what I meant, it shouldn't happen, thank you.

SantiagoSotoC commented 1 day ago

Well I found the error, snapcast is detecting silence in the stream between song and song. there is a parameter dryout_ms that solves it. I don't know how many ms would be adequate, a song can have a lot of silence in the middle and this error appears again, a large number introduces latency.

@marcelveldt Any suggestions ?