[solved] vlc as systemd unit cannot connect to audio servers

*nix specific usage questions
sparkyvision
New Cone
New Cone
Posts: 6
Joined: 19 May 2009 08:01

[solved] vlc as systemd unit cannot connect to audio servers

Postby sparkyvision » 28 Mar 2025 16:01

I'm trying to run vlc as a service, with telnet exposed so that my Home Assistant instance can use it as a media player. (A few other people have posted with issues somewhat like this, but one never got resolved and the other had solutions that did not solve my issue.)

The command is this:

ExecStart=/usr/bin/vlc --aout=alsa --role=notification -I telnet --telnet-port=4213 --telnet-password=VerySecurePassword --no-video --no-osd --no-one-instance -v

When running this interactively from the command line, the HA instance connects and functions exactly as intended. When running as a service, there is no audio output. Here is the units file:

Code: Select all

[Unit] Description=VLC Media Player - Telnet Service After=network.target [Service] Environment=DISPLAY=:0 Environment="PULSE_SERVER=127.0.0.1" ExecStart=/usr/bin/vlc --aout=alsa --role=notification -I telnet --telnet-port=4213 --telnet-password=VerySecurePassword --no-video --no-osd --no-one-instance -v Restart=on-failure User=sparkyvision [Install] WantedBy=multi-user.target

journalctl outputs this:

Code: Select all

Mar 27 20:12:23 ha-media vlc[76337]: [000060806c99a900] main audio output error: module not functional Mar 27 20:12:23 ha-media vlc[76337]: [00007af1c836bab0] main decoder error: failed to create audio output Mar 27 20:12:23 ha-media vlc[76337]: [000060806c99a900] alsa audio output error: cannot open ALSA device "default": Host is down Mar 27 20:12:23 ha-media vlc[76337]: [000060806c99a900] main audio output error: Audio output failed Mar 27 20:12:23 ha-media vlc[76337]: [000060806c99a900] main audio output error: The audio device "default" could not be used: Mar 27 20:12:23 ha-media vlc[76337]: Host is down.

Over and over and over again, until HA stops trying to play the file. The second I hit play, this gets output to the console.

Switching to PulseAudio gives the same result; connection happens without an issue when run interactively, but it will not work as a systemd unit. Also tried: aout=pipewire.

Code: Select all

vlcpulse audio output error: PulseAudio server connection failure: Connection refused
I suspect this is a permissions / user issue, but I'm stuck on how to troubleshoot / fix it...the logs aren't providing enough info to go on for me.

aplay -L gives the following:

Code: Select all

sparkyvision@ha-media:/etc/systemd/system$ aplay -L null Discard all samples (playback) or generate zero samples (capture) pipewire PipeWire Sound Server default Default ALSA Output (currently PipeWire Media Server) hw:CARD=HDMI,DEV=3 HDA Intel HDMI, HDMI 0 Direct hardware device without any conversions hw:CARD=HDMI,DEV=7 HDA Intel HDMI, HDMI 1 Direct hardware device without any conversions hw:CARD=HDMI,DEV=8 HDA Intel HDMI, HDMI 2 Direct hardware device without any conversions plughw:CARD=HDMI,DEV=3 HDA Intel HDMI, HDMI 0 Hardware device with all software conversions plughw:CARD=HDMI,DEV=7 HDA Intel HDMI, HDMI 1 Hardware device with all software conversions plughw:CARD=HDMI,DEV=8 HDA Intel HDMI, HDMI 2 Hardware device with all software conversions hdmi:CARD=HDMI,DEV=0 HDA Intel HDMI, HDMI 0 HDMI Audio Output hdmi:CARD=HDMI,DEV=1 HDA Intel HDMI, HDMI 1 HDMI Audio Output hdmi:CARD=HDMI,DEV=2 HDA Intel HDMI, HDMI 2 HDMI Audio Output dmix:CARD=HDMI,DEV=3 HDA Intel HDMI, HDMI 0 Direct sample mixing device dmix:CARD=HDMI,DEV=7 HDA Intel HDMI, HDMI 1 Direct sample mixing device dmix:CARD=HDMI,DEV=8 HDA Intel HDMI, HDMI 2 Direct sample mixing device hw:CARD=PCH,DEV=0 HDA Intel PCH, CS4208 Analog Direct hardware device without any conversions hw:CARD=PCH,DEV=1 HDA Intel PCH, CS4208 Digital Direct hardware device without any conversions plughw:CARD=PCH,DEV=0 HDA Intel PCH, CS4208 Analog Hardware device with all software conversions plughw:CARD=PCH,DEV=1 HDA Intel PCH, CS4208 Digital Hardware device with all software conversions sysdefault:CARD=PCH HDA Intel PCH, CS4208 Analog Default Audio Device front:CARD=PCH,DEV=0 HDA Intel PCH, CS4208 Analog Front output / input surround21:CARD=PCH,DEV=0 HDA Intel PCH, CS4208 Analog 2.1 Surround output to Front and Subwoofer speakers surround40:CARD=PCH,DEV=0 HDA Intel PCH, CS4208 Analog 4.0 Surround output to Front and Rear speakers surround41:CARD=PCH,DEV=0 HDA Intel PCH, CS4208 Analog 4.1 Surround output to Front, Rear and Subwoofer speakers surround50:CARD=PCH,DEV=0 HDA Intel PCH, CS4208 Analog 5.0 Surround output to Front, Center and Rear speakers surround51:CARD=PCH,DEV=0 HDA Intel PCH, CS4208 Analog 5.1 Surround output to Front, Center, Rear and Subwoofer speakers surround71:CARD=PCH,DEV=0 HDA Intel PCH, CS4208 Analog 7.1 Surround output to Front, Center, Side, Rear and Woofer speakers iec958:CARD=PCH,DEV=0 HDA Intel PCH, CS4208 Digital IEC958 (S/PDIF) Digital Audio Output dmix:CARD=PCH,DEV=0 HDA Intel PCH, CS4208 Analog Direct sample mixing device dmix:CARD=PCH,DEV=1 HDA Intel PCH, CS4208 Digital Direct sample mixing device
Oh, it's Linux Mint 22.
Last edited by sparkyvision on 29 Mar 2025 14:00, edited 1 time in total.

Rémi Denis-Courmont
Developer
Developer
Posts: 15358
Joined: 07 Jun 2004 16:01
VLC version: master
Operating System: Linux
Contact:

Re: vlc as systemd unit cannot connect to audio servers

Postby Rémi Denis-Courmont » 29 Mar 2025 08:36

The VLC unit needs to depend on the sound server service. Alternatively, use ALSA directly (but then no other app will be able to use audio).

This is more of a PA or PW problem; this would affect essentially any app, so this forum might not be the best place to get good answers, TBH.
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded

sparkyvision
New Cone
New Cone
Posts: 6
Joined: 19 May 2009 08:01

Re: vlc as systemd unit cannot connect to audio servers

Postby sparkyvision » 29 Mar 2025 14:00

For my use case, I do not care about anything else using audio. (Currently, maybe that will change in the future and then maybe I'll care.)

The solution was to add this line to my units config:

Code: Select all

Environment=XDG_RUNTIME_DIR=/run/user/1000
This forces the command to run as my user. It should work for you too, assuming your user number is 1000.

PS: I did actually try to use ALSA directly, but got the same "host is down" issue.

Rémi Denis-Courmont
Developer
Developer
Posts: 15358
Joined: 07 Jun 2004 16:01
VLC version: master
Operating System: Linux
Contact:

Re: [solved] vlc as systemd unit cannot connect to audio servers

Postby Rémi Denis-Courmont » 29 Mar 2025 16:23

"Host is down" is not an error you'd get using ALSA directly. You're probably using the ALSA wrapper for PA or PW.
Rémi Denis-Courmont
https://www.remlab.net/
Private messages soliciting support will be systematically discarded


Return to “VLC media player for Linux and friends Troubleshooting”

Who is online

Users browsing this forum: No registered users and 27 guests