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.37k stars 52 forks source link

Track playing freezes after around 1min #522

Closed SeByDocKy closed 2 years ago

SeByDocKy commented 2 years ago

What version of Music Assistant has the issue?

2022.6.5, 2022.6.6

The problem

I got a Raspiaudio ESPmuse luxe w/ ESPHome + MA combo. Everything was working fine ... but with recent MA updates I noticed that play MP3 freezes after about 1min/1min-15 with some glitches noise. It pauses like this during about 40s-1min, then resuming playing 3-4s... then freeze again during 3-4s.... Very annoying. Few important complements i) when streaming radio, there is no problem ii) when freezeing, the ESPhome logs can still show received events (pause/play/volume)... so seems not an ESPhome problem. iii) When freezing, if I change the mp3 song, it resumes to play the new selected song immediatly.

My 2 cents... seems to be a problem of streaming...

How to reproduce

Just play a mp3 track.... (stored in /media/ HA folder)

Relevant log output

No response

Additional information

No response

What version of Home Assistant Core are your running

2022.6.7

What type of installation are you running?

Home Assistant OS

On what type of hardware are you running?

ODROID

erkr commented 2 years ago

Hi, sorry to hear streaming fails for you. Can you recall if the issue started with the latest MA, or with the latest Core update? Additionally I expect there are related errors in your log. Please add them to the issue.

SeByDocKy commented 2 years ago

Hummmm as far I remember it started from last MA update even if in 2022.6.5 suffers also from this.

I have that in the log, not sure it's related:

Source: /usr/local/lib/python3.9/site-packages/music_assistant/music_providers/filesystem.py:495
First occurred: 8:37:47 AM (8 occurrences)
Last logged: 8:41:33 AM

/media/Nimbus.mp3 is missing ID3 tags, using filename as fallback
marcelveldt commented 2 years ago

For music streaming I strongly suggest to load the squeezelite firmware onto the Muse Luxe speaker. Although the ESPHome firmware should work it is pretty much limited and mainly created for broadcasting TTS messages. If your main goal is to stream music to the Luxe speaker I'd recommend the squeezelite firmware.

That said, I will have a look what's going on... Might be a buffering issue or the ESP32 audio library (not0 trying to decode the metadata packets that can optionally be requested in the stream. I will test this on my Muse speaker later today or tomorrow if I can reproduce.

SeByDocKy commented 2 years ago

For music streaming I strongly suggest to load the squeezelite firmware onto the Muse Luxe speaker. Although the ESPHome firmware should work it is pretty much limited and mainly created for broadcasting TTS messages. If your main goal is to stream music to the Luxe speaker I'd recommend the squeezelite firmware.

That said, I will have a look what's going on... Might be a buffering issue or the ESP32 audio library (not0 trying to decode the metadata packets that can optionally be requested in the stream. I will test this on my Muse speaker later today or tomorrow if I can reproduce.

Thanks a lot .... but was working fine w/ ESPHome until last week....

marcelveldt commented 2 years ago

Read my response more carefully please. I will take a look at the issue but still I recommend the squeezelite firmware ;-)

SeByDocKy commented 2 years ago

Read my response more carefully please. I will take a look at the issue but still I recommend the squeezelite firmware ;-)

Yes I will :)

marcelveldt commented 2 years ago

Just tested this with the upcoming 2022.6.7 release and I do (no longer) experience any buffering issues

marcelveldt commented 2 years ago

should be fixed in 2022.6.7, if not please reopen, thanks!

SeByDocKy commented 2 years ago

Tested with last 2022.6.9.... Still freezing.... For information, I noticed when happening the CPU usage jumps above 60% for my Ordroid C4.

marcelveldt commented 2 years ago

I still can't reproduce so a few questions:

SeByDocKy commented 2 years ago

i) yes from Local file (/media/ for my HASSIO/Odroid C4) ii) yes iii) Freezeless from Tunin (max CPU usage about 25-30%) iv) can't downgrade < 2022.6.5 :( from HACS :(

If you want I can share a small vidéo showing all problems

marcelveldt commented 2 years ago

I really can't reproduce this issue, sorry. Playback works fine. No stuttering, no high cpu usage, nothing. I tried several songs, both local files and online streaming providers. It just works.

One thing to consider: Are your music files local or mounted from an external NAS or something ? Maybe that is related ?

You do not have a streaming provider to test with ?

SeByDocKy commented 2 years ago

I really can't reproduce this issue, sorry. Playback works fine. No stuttering, no high cpu usage, nothing. I tried several songs, both local files and online streaming providers. It just works.

One thing to consider: Are your music files local or mounted from an external NAS or something ? Maybe that is related ?

No, everything is on my eMMC drive (64GB/12.4GB left)

You do not have a streaming provider to test with ?

No ... I tried to setup a free spotify account, but MA refused to accept my username.... don't know why. Should I setup first spotify integretion ?

marcelveldt commented 2 years ago

Free spotify accounts are not supported, only premium/paid accounts.

I left it playing for hours without a single glitch, tried with online and offline music sources.

Hmm, I just saw that I'm still running an early test version of the ESPHome component. I'll update the speaker to the latest official ESPHome version and try again.

SeByDocKy commented 2 years ago

From my side I reflashed everything from scratch .... still the same problem... (I tried from both ESPhome & ESPhome dev) I got also a basic raspiaudio proto.... and retrying everything and it freezes also about 1min.... so I can't accuse my Luxe model :( :(....

I am a bit lost :(...

EDIT:

I don't really believe that for some obscurs reason, from my /media/ local folder, playing is buggy. Another remark, when a mp3 freezes, I can rewing or forward for few second and it resumes to play....

I should do a video....

erkr commented 2 years ago

Just looking at this issue from a distance:

Although you have an eMMC drive, let's exclude there is not for example a disk issue or network issues.

1: do you have other players that work fine with these local files? 2: If not, You could try to install the VLC add on, and then the VLC telnet integration to enable local playback (no network dependency)

Best Eric

SeByDocKy commented 2 years ago

Ok will test that...with VLC. In //, I am uploading a video file .... I will edit this message with the link

EDIT : https://www.youtube.com/watch?v=-a1g7q9L8J0&feature=youtu.be

erkr commented 2 years ago

Ok will test that...with VLC.

EDIT : https://www.youtube.com/watch?v=-a1g7q9L8J0&feature=youtu.be

Thanks for uploading your video. It's not very sharp, but if I see it correctly, this was a specific test with esphome. It indeed looks like a buffering issue.

Thinking along with Marcel, two questions:

marcelveldt commented 2 years ago

I think you should really try to test it with another media player like VLC, google cast or just try flashing squeezelite on the Muse. I really can not reproduce any buffering issues. I just re-flashed my Muse speaker with ESPHome using this config: https://raw.githubusercontent.com/esphome/media-players/main/raspiaudio-muse-luxe.yaml

Again, no issues at all. It works flawless.

SeByDocKy commented 2 years ago

I am waiting for some basic speaker to test VLC telet on my Odroid.... I should receive them tmr.... I will test also squeezelite

erkr commented 2 years ago

If you have an 3.5 Jack, any headphone will serve fine!

patdemko commented 2 years ago

Just thought I'd mention that I see this same issue on my Muse Speaker running ESPHome when trying to play any Spotify music through it with Music Assistant. I am able to stream any of the radio streams from the radio browser to it without an issue (assuming the bitrates are a lot less). I haven't been able to test streaming radio through it with Music Assistant since the radio icon is grayed out in my instance for some reason that I haven't been able to figure out.
image

Also thought I'd mention that I'm running ESPhome on it instead of the squeezelite firmware since it doesn't seem to work when the local home assistant server is using HTTPS. I do not think the squeezelite firmware supports HTTPS based on some log entries I saw when trying to use it.

SeByDocKy commented 2 years ago

Just thought I'd mention that I see this same issue on my Muse Speaker running ESPHome when trying to play any Spotify music through it with Music Assistant. I am able to stream any of the radio streams from the radio browser to it without an issue (assuming the bitrates are a lot less). I haven't been able to test streaming radio through it with Music Assistant since the radio icon is grayed out in my instance for some reason that I haven't been able to figure out. image

Also thought I'd mention that I'm running ESPhome on it instead of the squeezelite firmware since it doesn't seem to work when the local home assistant server is using HTTPS. I do not think the squeezelite firmware supports HTTPS based on some log entries I saw when trying to use it.

OMG thanks I am not alone with this problem :).....

I am trying to use telnet VLC (I bought some USB speaker for).... but no sound is outputed .... and no particulary error.

@patdemko to add some radio in tune in, you have first to add each radio chanel as favorite (press on heart) then after a "reload" of MA, your radios should appear

marcelveldt commented 2 years ago

The only thing I can imagine is that this has something to do with the limited buffer size on the ESP in relation to WiFi networking or something like that. I did change the buffer size a while ago but I made it a bit larger which is good for most players but maybe it hurts the ESPHome based players. I still can't reproduce it though.

@patdemko slimproto works fine when HA is running over HTTPS, especially with Music Assistant because the slimproto integration in HA is actually the first building block that was contributed from MA into HA core ;-)

patdemko commented 2 years ago

The only thing I can imagine is that this has something to do with the limited buffer size on the ESP in relation to WiFi networking or something like that. I did change the buffer size a while ago but I made it a bit larger which is good for most players but maybe it hurts the ESPHome based players. I still can't reproduce it though.

@patdemko slimproto works fine when HA is running over HTTPS, especially with Music Assistant because the slimproto integration in HA is actually the first building block that was contributed from MA into HA core ;-)

I do think you're right about it being related to the buffer size in some manner. Since the Muse is on a different network than HA for me, I was able to grab a pcap between the two from my firewall. It appears after filling up the TCP window a few times the data just stops coming from the Home Assistant side even though the window opened back up. Then after about 50s the ESPHome side closes the TCP stream which I assume is because it stopped getting packets from the other end. Now when I looked at a similar pcap for streaming radio through Music Assistant (thanks @SeByDocKy for figuring out my issue), I see the same issues with the TCP window filling up and then opening back up. but I never see the music stream stop towards the ESPhome device. So not sure why that would be different than the spotify stream.

image

@marcelveldt as for using slimproto with HTTPS, it was mainly in regards to TTS not working. I posted in the forums and someone else also had the same issue. I don't think I still have the logs, but the error was because the URL getting passed to the Muse player for TTS was an HTTPS stream which it said it didn't support. I ended up getting around it by setting up LMS in docker and pointing the squeezelite player to that, but I would rather not have to run LMS just for that which is why I then switched to using ESPHome. :) I also think that since I'm running Home Assistant and the Muse player on different subnets that may also be causing issues with some of the auto discovery stuff but not sure if it's related or not.

If there are any logs or things you think I could capture that would help with this, please let me know.

marcelveldt commented 2 years ago

Can you please give version 2022.7 beta 1 a try ? I think I fixed this one today as I revamped the buffering. Thanks!

SeByDocKy commented 2 years ago

I installed this beta it but I am still on HA 2022.6.7 and got

Unable to prepare setup for platform mass.number: Platform not found (Exception importing custom_components.mass.number).
8:04:16 AM – (ERROR) setup.py
Unexpected exception importing platform custom_components.mass.number
8:04:16 AM – (ERROR) Music Assistant (custom integration)
marcelveldt commented 2 years ago

As stated in the release notes... MA release 2022.7.x is compatible with HA 2022.7.x only

patdemko commented 2 years ago

I just installed the beta and so far it looks good! I was just able to play two spotify songs in a row without having any issues. Previously I could never get past halfway through the first song. Thanks for digging into this and appearing to fix it!!!

marcelveldt commented 2 years ago

OK very cool to know that it seems to be fixed. Let's wait for @SeByDocKy if he confirms the same and then we can close this issue.

SeByDocKy commented 2 years ago

OK very cool to know that it seems to be fixed. Let's wait for @SeByDocKy if he confirms the same and then we can close this issue.

Ok so far so good also for me .... no more problem from my local mp3 files :) ... Great job @marcelveldt

marcelveldt commented 2 years ago

fantastic!