You are not logged in.

#1 2021-10-04 07:49:35

Goldman
Member
Registered: 2021-01-29
Posts: 11

Getting systemd to play audio through HDMI

My systemd service run smplayer and it output sound through device 0: ALC892 Analog but there is only HDMI connected to my computer. How can I set systemd config to play sound through HDMI?

[Unit]
Description=bot
After=syslog.target network.target sound.target
[Service]
Environment=DISPLAY=:0
Type=simple
User=myname
Group=users
ExecStart=/opt/bot/bot.sh
[Install]
WantedBy=default.target

$ aplay -l

**** List of PLAYBACK Hardware Devices ****
card 0: PCH [HDA Intel PCH], device 0: ALC892 Analog [ALC892 Analog]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 1: ALC892 Digital [ALC892 Digital]
  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 0: PCH [HDA Intel PCH], device 7: HDMI 1 [HDMI 1]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 8: HDMI 2 [HDMI 2]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 9: HDMI 3 [HDMI 3]
  Subdevices: 1/1
  Subdevice #0: subdevice #0
card 0: PCH [HDA Intel PCH], device 10: HDMI 4 [HDMI 4]
  Subdevices: 1/1
  Subdevice #0: subdevice #0

Offline

#2 2021-10-04 09:01:43

Lone_Wolf
Member
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 9,509

Re: Getting systemd to play audio through HDMI

systemd does many things, but sound config is not one of them.

I'd like to know what alsa sees as default output device, pleas post aplay --list-pcms


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.
Did you use the guided installer ? If yes, I can't help you.

(A works at time B)  && (time C > time B ) ≠  (A works at time C)

Offline

#3 2021-10-04 10:22:07

Goldman
Member
Registered: 2021-01-29
Posts: 11

Re: Getting systemd to play audio through HDMI

Lone_Wolf wrote:

pleas post aplay --list-pcms

$ aplay --list-pcms
null
    Discard all samples (playback) or generate zero samples (capture)
samplerate
    Rate Converter Plugin Using Samplerate Library
speexrate
    Rate Converter Plugin Using Speex Resampler
jack
    JACK Audio Connection Kit
oss
    Open Sound System
pipewire
    PipeWire Sound Server
pulse
    PulseAudio Sound Server
speex
    Plugin using Speex DSP (resample, agc, denoise, echo, dereverb)
upmix
    Plugin for channel upmix (4,6,8)
vdownmix
    Plugin for channel downmix (stereo) with a simple spacialization
default
    Default ALSA Output (currently PulseAudio Sound Server)
sysdefault:CARD=PCH
    HDA Intel PCH, ALC892 Analog
    Default Audio Device
front:CARD=PCH,DEV=0
    HDA Intel PCH, ALC892 Analog
    Front output / input
surround21:CARD=PCH,DEV=0
    HDA Intel PCH, ALC892 Analog
    2.1 Surround output to Front and Subwoofer speakers
surround40:CARD=PCH,DEV=0
    HDA Intel PCH, ALC892 Analog
    4.0 Surround output to Front and Rear speakers
surround41:CARD=PCH,DEV=0
    HDA Intel PCH, ALC892 Analog
    4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=PCH,DEV=0
    HDA Intel PCH, ALC892 Analog
    5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=PCH,DEV=0
    HDA Intel PCH, ALC892 Analog
    5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=PCH,DEV=0
    HDA Intel PCH, ALC892 Analog
    7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
iec958:CARD=PCH,DEV=0
    HDA Intel PCH, ALC892 Digital
    IEC958 (S/PDIF) Digital Audio Output
hdmi:CARD=PCH,DEV=0
    HDA Intel PCH, HDMI 0
    HDMI Audio Output
hdmi:CARD=PCH,DEV=1
    HDA Intel PCH, HDMI 1
    HDMI Audio Output
hdmi:CARD=PCH,DEV=2
    HDA Intel PCH, HDMI 2
    HDMI Audio Output
hdmi:CARD=PCH,DEV=3
    HDA Intel PCH, HDMI 3
    HDMI Audio Output
hdmi:CARD=PCH,DEV=4
    HDA Intel PCH, HDMI 4
    HDMI Audio Output
usbstream:CARD=PCH
    HDA Intel PCH
    USB Stream Output

I tried to set  in /etc/pulse/default.pa but it did not result.

set-default-sink output alsa_output.pci-0000_00_0e.0.hdmi-stereo

Offline

#4 2021-10-04 10:48:17

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 14,088

Re: Getting systemd to play audio through HDMI

Pulseaudio is not running by the time you start smplayer. What's your actual intention here? What's the content of your script? If you just want an "autostart" when you log in make the service an --user service.  https://wiki.archlinux.org/title/Systemd/User

[Unit]
Description=bot
After=pulseaudio.service
[Service]
Type=simple
ExecStart=/opt/bot/bot.sh
[Install]
WantedBy=default.target

put it into a systemd user service location like described in the linked article and enable it with

systemctl --user enable bot.service

if you really want to run this as a systemd service regardless of the logged in user  you'd need to change the default device of mplayer/smplayer so it uses hw:0,3

Offline

#5 2021-10-04 11:55:26

Goldman
Member
Registered: 2021-01-29
Posts: 11

Re: Getting systemd to play audio through HDMI

V1del wrote:

Pulseaudio is not running by the time you start smplayer. What's your actual intention here? What's the content of your script? If you just want an "autostart" when you log in make the service an --user service.

It is a telegram bot who play some videos by command in current desktop session. Also it implements some other stuff like monitoring so it's better to start before user log in.
So is there is no options to set audio output in systemd like Display:0, I suppose there are two ways:
1. set default audio to HDMI in whole system.
2. find a way to set up HDMI in smplayer config or by command when run some videos.
I will try to manage them. Thank you!

Offline

#6 2021-10-04 13:05:36

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 14,088

Re: Getting systemd to play audio through HDMI

If it's for the current desktop session then running it as part of the current desktop session via an user service is definitely the better approach and this will make sure you can actually connect to a pulse server that then has the correct default setup.

Offline

#7 2021-10-04 15:16:08

Goldman
Member
Registered: 2021-01-29
Posts: 11

Re: Getting systemd to play audio through HDMI

V1del wrote:

If it's for the current desktop session then running it as part of the current desktop session via an user service is definitely the better approach and this will make sure you can actually connect to a pulse server that then has the correct default setup.

Really when service running as -user, sound work correct. Thank you guys!
SOLVED

Offline

Board footer

Powered by FluxBB