Multi-room audio with Snapcast, Mopidy, and Home Assistant

So more debuging…

If I set the port to 1704 in Mopidy I get the following in the snapcast server log:

2021-01-18 10-08-38.260 [Notice] (StreamServer) StreamServer::NewConnection: 192.168.1.xxx
2021-01-18 10-08-38.261 [Error] (StreamSessionTCP) unknown message type received: 790, size: 2477441087
2021-01-18 10-08-38.261 [Info] (StreamServer) onDisconnect: 
2021-01-18 10-08-38.275 [Notice] (StreamServer) StreamServer::NewConnection: 192.168.1.xxx
2021-01-18 10-08-38.275 [Error] (StreamSessionTCP) unknown message type received: 790, size: 1372112756
2021-01-18 10-08-38.275 [Info] (StreamServer) onDisconnect:

If I change it to port 1705 (this crashes snapcast):

2021-01-18 10-12-59.392 [Notice] (ControlServer) ControlServer::NewConnection: 192.168.1.xxx
2021-01-18 10-12-59.393 [Error] (ControlSessionTCP) Error while reading from control socket: End of file
2021-01-18 10-12-59.393 [Error] (ControlSessionTCP) Error in socket shutdown: Socket not connected
2021-01-18 10-12-59.406 [Notice] (ControlServer) ControlServer::NewConnection: 192.168.1.xxx
2021-01-18 10-12-59.407 [Error] (ControlServer) Removing 1 inactive session(s), active sessions: 1
terminate called after throwing an instance of 'nlohmann::detail::type_error'
  what():  [json.exception.type_error.316] invalid UTF-8 byte at index 95: 0xAE
/run.sh: line 43:   236 Aborted                 (core dumped) /usr/bin/snapserver -c /etc/snapserver.conf
[cmd] /run.sh exited 134
[cont-finish.d] executing container finish scripts...
[cont-finish.d] done.
[s6-finish] waiting for services.
[s6-finish] sending all processes the TERM signal.

If I change it back to port 1780, I get:

2021-01-18 11-00-58.556 [Notice] (ControlServer) ControlServer::NewConnection: 192.168.1.xxx
2021-01-18 11-00-58.557 [Error] (ControlSessionHTTP) ControlSessionHttp::on_read error: bad method
2021-01-18 11-00-58.571 [Notice] (ControlServer) ControlServer::NewConnection: 192.168.1.xxx
2021-01-18 11-00-58.571 [Error] (ControlServer) Removing 1 inactive session(s), active sessions: 1
2021-01-18 11-00-58.571 [Error] (ControlSessionHTTP) ControlSessionHttp::on_read error: bad method

Port 1704 and 1705 will not work, 1780 is the correct port.

What issue is there with port 1780 in nginx?

You can’t upgrade mopidy like this, because you are running it in a docker container.

And the snapclient on the phone lets you connect to the snapserver with local ip and port 1780? Can you also connect to the snapserver from a computer with local IP and port 1780?

When using my PC’s browser and using 192.168.1.XXX:1780 I get:

The resource ‘/’ was not found.
2021-01-18_13-23-33

On my phone it uses:
stream port: 1704
control port: 1705

which one should I change to 1780 for testing?

I noticed this may be the issue:
your [http] doc_root in /etc/snapserver.conf should point to your snapweb directory (default /usr/share/snapserver/snapweb ).

Where do I find all the conf files within Hassio?

Ok, just checked my settings and I realized now that the snapcast section in Mopidy settings is only used to enable control of the snapclient volumes from mopidy, but not to get the mopidy stream to be available in snapserver as a stream.

When I go to ip-of-snapserver:1780, I get the snapcast control interface.

Can you please show the config of the mopidy add-on? Do you see the spotify connect stream from the snapserver on your phone? When you open the snapcast app on the phone can you choose Mopidy as a source?

this is my modipy config:

system_packages: []
python_packages: []
settings:
  - name: soundcloud/auth_token
    value: xxxxxxx
  - name: spotify/username
    value: xxxxx
  - name: spotify/password
    value: xxxxx
  - name: spotify/client_id
    value: xxxxx
  - name: spotify/client_secret
    value: xxxxxxx
  - name: youtube/enabled
    value: 'true'
  - name: youtube/playlist_max_videos
    value: '300'
  - name: file/enabled
    value: 'true'
  - name: file/media_dirs
    value: /share/mopidy/media
  - name: audio/output
    value: >-
      audioresample ! audio/x-raw,rate=44100,channels=2,format=S16LE !
      audioconvert ! wavenc ! filesink location=/share/snapfifo/mopidy

In my Snapcast mobile app I see my phone and I can switch between mopidy and spotifyconnect, but I don’t see much on there…

2021-01-18_13-51-25

ok, that looks good so far.

Next test, on your phone in the spotify app connect to the snapserver spotify connect and play a track. Then in the snapcast start the app by pressing the play button in the top right and change the source to “SpotifyConnect”, do you hear music?

Next play something on mopidy, then again on your phone change the source to Mopidy in the snapcast app, do you hear music?

OK so SpotifyConnect played the song flawlessly
Mopidy didn’t play the song I was playing in Mopidy but a loop of another song, was jittery too and stuck in a loop.

Try stopping mopidy and then snapserver, then start mopidy first and snapserver afterwards and see if the issue persists.

it’s still stuck at that same looped song…cached somewhere
Did several stops/start, rebooted my phone, hassio, nothing helps.

In snapserver it shows tons of similar lines:

2021-01-18 14-24-36.003 [Info] (PosixStream) next read < 0 (Mopidy): -2.035 ms
2021-01-18 14-24-36.163 [Info] (PosixStream) next read < 0 (Mopidy): -2.333 ms
2021-01-18 14-24-36.260 [Info] (PosixStream) next read < 0 (Mopidy): -19.32 ms
2021-01-18 14-24-36.344 [Info] (PosixStream) next read < 0 (Mopidy): -3.9 ms
2021-01-18 14-24-36.405 [Info] (PosixStream) next read < 0 (Mopidy): -4.826 ms
2021-01-18 14-24-36.765 [Info] (PosixStream) next read < 0 (Mopidy): -4.382 ms
2021-01-18 14-24-36.969 [Info] (PosixStream) next read < 0 (Mopidy): -28.625 ms
2021-01-18 14-24-36.969 [Info] (PosixStream) next read < 0 (Mopidy): -8.938 ms
2021-01-18 14-24-37.650 [Info] (PosixStream) next read < 0 (Mopidy): -9.803 ms
2021-01-18 14-24-37.741 [Info] (PosixStream) next read < 0 (Mopidy): -0.474 ms

try removing the files in share/snapfifo/mopidy

ok that finally stopped the looped music :slight_smile:

Also now did the Mopidy test and it works over the mobile phone. So I can hear the song playing from Mopidy on my phone.

BTW will I be able to add Amazon Echo as players on this?

1 Like

No. Each player needs to run the snapclient software.

1 Like

So can it be run on my Nvidia Shield?

looks like it works -> https://github.com/badaix/snapdroid/issues/3#issuecomment-448055956

I’m a long time Squeezebox/LMS user as well and have started the Home Assistant journey about a year ago. Just reading about this and it sounds awesome.
Do you essentially get full access to the players from HA to play local music, stream music and sync? Does it work reliably?

This doc may be helpful

1 Like

I’m now using forked-daapd (docker) for multiroom audio using Google cast and/or AirPlay. It has a media_player integration and Spotify support, as well. Works great and easy to setup. Worth checking out as an alternative to mopidy.
https://hub.docker.com/r/linuxserver/daapd

Thanks. That’s so easy and just works. However it looks like it doesn’t support apps. I’m running Spotify through LMS through a custom plugin.

The plugin is accessed via the My Apps menu. It looks like this integration picks up local music. Still a good start