tryffel / jellycli

Jellyfin terminal client
GNU General Public License v3.0
206 stars 8 forks source link

Select specific Alsa ouput device #16

Closed millallo closed 3 years ago

millallo commented 3 years ago

Hi, is it possible to select a specific device for output in Linux? I have these sound cards:

# aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: ALC255 Analog [ALC255 Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 3: HDMI 0 [HDMI 0]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 1: U0xccd0x77 [USB Device 0xccd:0x77], device 0: USB Audio [USB Audio]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

And i would like to use card1 device0 (hw:1,0) which has an SPDIF link to my HiFi system.

tryffel commented 3 years ago

At least with KDE you can change audio output device directly in sound settings. Which desktop are you using?

millallo commented 3 years ago

I don't have a desktop, only a CLI server with jellyfin and i would like to use as a player with jellycli also. I found the workaround creating inside the home dir of the jellycli user the file named .asoundrc with this content:

pcm.!default {
        type hw
        card 1
}

ctl.!default {
        type hw
        card 1
}

This overrides the 'default' Alsa card (which usually is 0) to my preferred 1

Thanks

jwillikers commented 2 years ago

It's probably better to specify the card by name instead of index.

cat /proc/asound/cards
 0 [Loopback       ]: Loopback - Loopback
                      Loopback 1
 1 [IQaudIODAC     ]: IQaudIODAC - IQaudIODAC
                      IQaudIODAC
 2 [vc4hdmi0       ]: vc4-hdmi - vc4-hdmi-0
                      vc4-hdmi-0
 3 [vc4hdmi1       ]: vc4-hdmi - vc4-hdmi-1
                      vc4-hdmi-1
pcm.!default {
    type hw
    card IQaudIODAC
}

ctl.!default {
    type hw
    card IQaudIODAC
}

Perhaps this should be added to the documentation?

jwillikers commented 2 years ago

Actually, it's even easier to configure this with the environment variable ALSA_CARD in the container.

sudo podman run \
  -it \
  --device /dev/snd \
  --env ALSA_CARD=IQaudIODAC \
  --label "io.containers.autoupdate=registry" \
  --name jellycli \
  --rm \
  --volume jellycli-config:/root/.config:Z \
  localhost/jellycli:latest --no-gui

Further granularity for the output device can be configured with ALSA_PCM_DEVICE. Such as when you want audio to be played through a specific loopback device.

sudo podman run \
  -it \
  --device /dev/snd \
  --env ALSA_CARD=Loopback \
  --env ALSA_PCM_DEVICE=0 \
  --label "io.containers.autoupdate=registry" \
  --name jellycli \
  --rm \
  --volume jellycli-config:/root/.config:Z \
  localhost/jellycli:latest --no-gui