sweisgerber / docker-snapcast

Snapcast Multiroom audio docker image
7 stars 5 forks source link

Can't open soundcard #8

Open tylor-e opened 3 months ago

tylor-e commented 3 months ago

I use hifiberry_dacplus to play music. I can use "aplay xxx.wav" to hear my sound. But when I use snapclient, I configure "- SNAPCLIENT_OPTS=--host 192.168.100.64 --soundcard 1". It shows errors like follows:

snapcast_1 | 2024-03-27 00-49-37.908 [Error] (Snapclient) PCM device "1" not found snapcast_1 | 2024-03-27 00-49-37.908 [Info] (Snapclient) Version 0.27.0 snapcast_1 | 2024-03-27 00-49-37.908 [Info] (Connection) Resolving host IP for: 192.168.100.64 snapcast_1 | 2024-03-27 00-49-37.908 [Info] (Connection) Connecting snapcast_1 | 2024-03-27 00-49-37.915 [Notice] (Connection) Connected to 192.168.100.64 snapcast_1 | 2024-03-27 00-49-37.915 [Info] (Connection) My MAC: "02:42:ac:12:00:02", socket: 8 snapcast_1 | 2024-03-27 00-49-37.939 [Info] (Controller) ServerSettings - buffer: 1000, latency: 0, volume: 100, muted: 0 snapcast_1 | 2024-03-27 00-49-37.939 [Info] (Controller) Codec: pcm, sampleformat: 48000:16:2 snapcast_1 | 2024-03-27 00-49-37.939 [Info] (Player) Player name: alsa, device: 1, description: , idx: -1, sharing mode: unspecified, parameters: snapcast_1 | 2024-03-27 00-49-37.939 [Info] (Player) Mixer mode: software, parameters: snapcast_1 | 2024-03-27 00-49-37.939 [Info] (Player) Sampleformat: 48000:16:2, stream: 48000:16:2 snapcast_1 | 2024-03-27 00-49-37.940 [Info] (Alsa) Using default buffer_time: 80 ms, default fragments: 4 snapcast_1 | ALSA lib pcm.c:2721:(snd_pcm_open_noupdate) Unknown PCM 1 snapcast_1 | 2024-03-27 00-49-37.954 [Error] (Alsa) Exception: Can't open 1, error: No such file or directory, code: -2 snapcast_1 | 2024-03-27 00-49-37.956 [Fatal] (Snapclient) Exception: Can't open 1, error: No such file or directory snapcast_1 | 2024-03-27 00-49-37.956 [Notice] (Snapclient) Snapclient terminated.

how can I fix this?

tylor-e commented 3 months ago

this fixed after I did nothing but went for business for a few days. Which means I shutdown the docker for 3 days.

however, it still cannot play any music. the log shows like below:

snapcast_1  | 2024-03-30 15-32-20.213 [Info] (Stream) abs(age > 500): 559390
snapcast_1  | 2024-03-30 15-32-20.213 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-20.773 [Info] (Stream) abs(age > 500): 559398
snapcast_1  | 2024-03-30 15-32-20.773 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-21.333 [Info] (Stream) abs(age > 500): 559369
snapcast_1  | 2024-03-30 15-32-21.333 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-21.893 [Info] (Stream) abs(age > 500): 559395
snapcast_1  | 2024-03-30 15-32-21.893 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-22.453 [Info] (Stream) abs(age > 500): 559386
snapcast_1  | 2024-03-30 15-32-22.453 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-23.013 [Info] (Stream) abs(age > 500): 559321
snapcast_1  | 2024-03-30 15-32-23.013 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-23.573 [Info] (Stream) abs(age > 500): 559457
snapcast_1  | 2024-03-30 15-32-23.573 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-24.133 [Info] (Stream) abs(age > 500): 559382
snapcast_1  | 2024-03-30 15-32-24.133 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-24.693 [Info] (Stream) abs(age > 500): 559406
snapcast_1  | 2024-03-30 15-32-24.693 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-25.253 [Info] (Stream) abs(age > 500): 559375
snapcast_1  | 2024-03-30 15-32-25.253 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-25.813 [Info] (Stream) abs(age > 500): 559392
snapcast_1  | 2024-03-30 15-32-25.813 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-26.373 [Info] (Stream) abs(age > 500): 559372
snapcast_1  | 2024-03-30 15-32-26.373 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-26.933 [Info] (Stream) abs(age > 500): 559409
snapcast_1  | 2024-03-30 15-32-26.933 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-27.493 [Info] (Stream) abs(age > 500): 559373
snapcast_1  | 2024-03-30 15-32-27.493 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-28.053 [Info] (Stream) abs(age > 500): 559337
snapcast_1  | 2024-03-30 15-32-28.053 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-28.613 [Info] (Stream) abs(age > 500): 559438
snapcast_1  | 2024-03-30 15-32-28.613 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-29.173 [Info] (Stream) abs(age > 500): 559390
snapcast_1  | 2024-03-30 15-32-29.173 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-29.733 [Info] (Stream) abs(age > 500): 559405
snapcast_1  | 2024-03-30 15-32-29.733 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-30.293 [Info] (Stream) abs(age > 500): 559399
snapcast_1  | 2024-03-30 15-32-30.293 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-30.853 [Info] (Stream) abs(age > 500): 559407
snapcast_1  | 2024-03-30 15-32-30.853 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-31.413 [Info] (Stream) abs(age > 500): 559348
snapcast_1  | 2024-03-30 15-32-31.413 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-31.973 [Info] (Stream) abs(age > 500): 559399
snapcast_1  | 2024-03-30 15-32-31.973 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-32.533 [Info] (Stream) abs(age > 500): 559377
snapcast_1  | 2024-03-30 15-32-32.533 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-33.093 [Info] (Stream) abs(age > 500): 559287
snapcast_1  | 2024-03-30 15-32-33.094 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-33.653 [Info] (Stream) abs(age > 500): 559449
snapcast_1  | 2024-03-30 15-32-33.653 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-34.214 [Info] (Stream) abs(age > 500): 559155
snapcast_1  | 2024-03-30 15-32-34.214 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-34.773 [Info] (Stream) abs(age > 500): 559394
snapcast_1  | 2024-03-30 15-32-34.774 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-35.333 [Info] (Stream) abs(age > 500): 559369
snapcast_1  | 2024-03-30 15-32-35.334 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-35.893 [Info] (Stream) abs(age > 500): 559399
snapcast_1  | 2024-03-30 15-32-35.894 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-36.453 [Info] (Stream) abs(age > 500): 559371
snapcast_1  | 2024-03-30 15-32-36.454 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-37.014 [Info] (Stream) abs(age > 500): 559334
snapcast_1  | 2024-03-30 15-32-37.014 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-37.573 [Info] (Stream) abs(age > 500): 559431
snapcast_1  | 2024-03-30 15-32-37.574 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-38.134 [Info] (Stream) abs(age > 500): 559134
snapcast_1  | 2024-03-30 15-32-38.134 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-38.694 [Info] (Stream) abs(age > 500): 559445
snapcast_1  | 2024-03-30 15-32-38.694 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-39.254 [Info] (Stream) abs(age > 500): 559303
snapcast_1  | 2024-03-30 15-32-39.254 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-39.814 [Info] (Stream) abs(age > 500): 559399
snapcast_1  | 2024-03-30 15-32-39.814 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-40.374 [Info] (Stream) abs(age > 500): 559384
snapcast_1  | 2024-03-30 15-32-40.374 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-40.934 [Info] (Stream) abs(age > 500): 559372
snapcast_1  | 2024-03-30 15-32-40.934 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-41.494 [Info] (Stream) abs(age > 500): 559420
snapcast_1  | 2024-03-30 15-32-41.494 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-42.054 [Info] (Stream) abs(age > 500): 559322
snapcast_1  | 2024-03-30 15-32-42.054 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-42.614 [Info] (Stream) abs(age > 500): 559432
snapcast_1  | 2024-03-30 15-32-42.614 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-43.174 [Info] (Stream) abs(age > 500): 559314
snapcast_1  | 2024-03-30 15-32-43.174 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-43.734 [Info] (Stream) abs(age > 500): 559443
snapcast_1  | 2024-03-30 15-32-43.734 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-44.294 [Info] (Stream) abs(age > 500): 559299
snapcast_1  | 2024-03-30 15-32-44.294 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-44.854 [Info] (Stream) abs(age > 500): 559372
snapcast_1  | 2024-03-30 15-32-44.854 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-45.414 [Info] (Stream) abs(age > 500): 559347
snapcast_1  | 2024-03-30 15-32-45.414 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-45.974 [Info] (Stream) abs(age > 500): 559165
snapcast_1  | 2024-03-30 15-32-45.974 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-46.534 [Info] (Stream) abs(age > 500): 559268
snapcast_1  | 2024-03-30 15-32-46.534 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-47.094 [Info] (Stream) abs(age > 500): 559333
snapcast_1  | 2024-03-30 15-32-47.094 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-47.654 [Info] (Stream) abs(age > 500): 559233
snapcast_1  | 2024-03-30 15-32-47.654 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-48.214 [Info] (Stream) abs(age > 500): 559344
snapcast_1  | 2024-03-30 15-32-48.214 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-48.774 [Info] (Stream) abs(age > 500): 559420
snapcast_1  | 2024-03-30 15-32-48.774 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-49.334 [Info] (Stream) abs(age > 500): 559387
snapcast_1  | 2024-03-30 15-32-49.334 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-49.894 [Info] (Stream) abs(age > 500): 559108
snapcast_1  | 2024-03-30 15-32-49.895 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-50.454 [Info] (Stream) abs(age > 500): 559368
snapcast_1  | 2024-03-30 15-32-50.454 [Info] (Alsa) Failed to get chunk

this loop ends when I pause the music, showing like below:

snapcast_1  | 2024-03-30 15-32-51.014 [Info] (Stream) Exception: Not enough frames available, requested frames: 3840, available: 3686
snapcast_1  | 2024-03-30 15-32-51.014 [Info] (Alsa) Failed to get chunk
snapcast_1  | 2024-03-30 15-32-56.020 [Notice] (Alsa) No chunk received for 5000ms. Closing ALSA.

I installed snapclient on both iOS and android phone, and both can get sound. I think my server workds well. but why the snapclient on my raspberry pi 3 cannot. Can anyone help?

sweisgerber commented 3 months ago

I use hifiberry_dacplus to play music. I can use "aplay xxx.wav" to hear my sound. But when I use snapclient, I configure "- SNAPCLIENT_OPTS=--host 192.168.100.64 --soundcard 1". It shows errors like follows:

snapcast_1 | 2024-03-27 00-49-37.908 [Error] (Snapclient) PCM device "1" not found snapcast_1 | 2024-03-27 00-49-37.908 [Info] (Snapclient) Version 0.27.0 snapcast_1 | 2024-03-27 00-49-37.908 [Info] (Connection) Resolving host IP for: 192.168.100.64 snapcast_1 | 2024-03-27 00-49-37.908 [Info] (Connection) Connecting snapcast_1 | 2024-03-27 00-49-37.915 [Notice] (Connection) Connected to 192.168.100.64 snapcast_1 | 2024-03-27 00-49-37.915 [Info] (Connection) My MAC: "02:42:ac:12:00:02", socket: 8 snapcast_1 | 2024-03-27 00-49-37.939 [Info] (Controller) ServerSettings - buffer: 1000, latency: 0, volume: 100, muted: 0 snapcast_1 | 2024-03-27 00-49-37.939 [Info] (Controller) Codec: pcm, sampleformat: 48000:16:2 snapcast_1 | 2024-03-27 00-49-37.939 [Info] (Player) Player name: alsa, device: 1, description: , idx: -1, sharing mode: unspecified, parameters: snapcast_1 | 2024-03-27 00-49-37.939 [Info] (Player) Mixer mode: software, parameters: snapcast_1 | 2024-03-27 00-49-37.939 [Info] (Player) Sampleformat: 48000:16:2, stream: 48000:16:2 snapcast_1 | 2024-03-27 00-49-37.940 [Info] (Alsa) Using default buffer_time: 80 ms, default fragments: 4 snapcast_1 | ALSA lib pcm.c:2721:(snd_pcm_open_noupdate) Unknown PCM 1 snapcast_1 | 2024-03-27 00-49-37.954 [Error] (Alsa) Exception: Can't open 1, error: No such file or directory, code: -2 snapcast_1 | 2024-03-27 00-49-37.956 [Fatal] (Snapclient) Exception: Can't open 1, error: No such file or directory snapcast_1 | 2024-03-27 00-49-37.956 [Notice] (Snapclient) Snapclient terminated.

how can I fix this?

Regarding your first error, either the docker host OS is using the device or you specified the wrong device. Try executing snapclient --list within the container and specify the proper id with --soundcard

Regarding error 2 (this is now wild guessing):

Do you have the same timezone / time on all clients. i interpret the error message as if snapclient drops the packages because they are too old?

tylor-e commented 3 months ago

I copied the docker-compose.yml from github, and made a few changes.

The server yml:

version: "3"
services:
  mopidy:
    image: docker.io/sweisgerber/mopidy:latest
    hostname: mopidy
    environment:
      - PUID=1000 # user ID which the mopidy service will run as, needs permissions to access the music
      - PGID=1000 # group ID which the mopidy service will run as, needs permissions to access the music
      - TZ=Asia/Shanghai
      #
      # https://github.com/linuxserver/docker-mods/tree/universal-package-install
      #
      # Set alpine or pip package ENV vars for further mopidy extensions
      #
      - DOCKER_MODS=linuxserver/mods:universal-package-install
      - INSTALL_PIP_PACKAGES=Mopidy-Beets|Mopidy-dLeyna|Mopidy-InternetArchive|Mopidy-TuneIn|Mopidy-YTMusic
      # - INSTALL_PACKAGES=mopidy-podcast
    restart: "unless-stopped"
    ports:
      - 6600:6600 # Remote Control port for MPD
      - 6680:6680 # HTML API & Webinterface port for accessing mopidy
    # devices:
    # - /dev/snd:/dev/snd # optional, needed if you want to play to host audio devices.
    volumes:
      - $MOPIROOM_FOLDER/config/:/config/
      # contains mopidy configured FIFO location,
      # check mopidy.conf <https://github.com/sweisgerber/docker-mopidy/blob/main/root/defaults/mopidy.conf>
      # will get used by snapcast and streamed to the network.
      #
      # ```conf
      # [audio]
      # output = (...) location=/data/audio/snapcast_fifo
      # ```
      #
      # mopidy--FIFO-in-FileSystem-->SnapServer--LAN-Stream-->SnapClient
      #
      - $MOPIROOM_FOLDER/data/:/data/
      - $MOPIROOM_FOLDER/:/music/:ro # READ-ONLY & optional  (needed if you want to play audio files from host)
# One should use snapcast along mopidy/iris, use https://github.com/sweisgerber/docker-snapcast/blob/main/docker-compose.example.yml
  snapcast:
    image: docker.io/sweisgerber/snapcast:latest
    hostname: snapcast
    environment:
      - PUID=1000
      - PGID=1000 # set to audio group ID
      - TZ=Asia/Shanghai
      - START_SNAPCLIENT=false # set to `true` for snapclient to start
      # --host: name or ip of compose service or dockerhost
      # --soundcard: <ID> from `snapclient -l` from inside the container
      # - SNAPCLIENT_OPTS=--host snapcast --soundcard <ID>
      #   => Don't use quotes for SNAPCLIENT_OPTS="" !
      - HOST_AUDIO_GROUP=1000 # set to GID of host audio group
    restart: "unless-stopped"
    ports:
      - 1704:1704
      - 1705:1705
      - 1780:1780
    # devices:
      # - /dev/snd:/dev/snd # optional, only if you want to use snapclient
    volumes:
      - $MOPIROOM_FOLDER/snapcast/config/:/config/
      - $MOPIROOM_FOLDER/snapcast/data/:/data/
      # /audio should get used to place FIFOs for audio playback from mpd/mopidy/host/etc
      - $MOPIROOM_FOLDER/data/audio/:/audio/

The client yml:

version: "3"
services:
  snapcast:
    image: docker.io/sweisgerber/snapcast:latest
    hostname: snapcast
    environment:
      - PUID=1000
      - PGID=1000 # set to audio group ID
      - TZ=Asia/Shanghai
      - START_SNAPCLIENT=true # set to `true` for snapclient to start
      # --host: name or ip of compose service or dockerhost
      # --soundcard: <ID> from `snapclient -l` from inside the container
      - SNAPCLIENT_OPTS=--host pi0 --soundcard 0
      #   => Don't use quotes for SNAPCLIENT_OPTS="" !
      - HOST_AUDIO_GROUP=996 # set to GID of host audio group
    restart: "unless-stopped"
    ports:
      - 1704:1704
      - 1705:1705
      - 1780:1780
    devices:
      - /dev/snd:/dev/snd # optional, only if you want to use snapclient
    volumes:
      - $SNAPCLIENT_FOLDER/snapcast/config/:/config/
      - $SNAPCLIENT_FOLDER/snapcast/data/:/data/
      # /audio should get used to place FIFOs for audio playback from mpd/mopidy/host/etc
      - $SNAPCLIENT_FOLDER/data/audio/:/audio/

I can control the client volume, delay, and all settings in real time. But error accurred everytime when I play some sound just like my 2nd post. I checked the timezones on both server and client, which turned to be correct just the same as RPi's.