启动时运行音频文件

启动时运行音频文件

我在 Raspberry PI4 上安装了 ubuntu 服务器。我希望这台 Raspberry 在启动时运行音频文件(无需我登录)。我创建了一个 audio.sh 文件,内容如下:

#!/bin/sh
cvlc --loop --intf=dummy  /home/user/musica.mp3

然后我创建了一个启动的服务(audio.service):

[Unit]
Description=Servizio Musica Showroom

[Service]
ExecStart=/home/user/audio.sh

[Install]
WantedBy=default.target

这导致启动时出现 pulseaudio 错误,因此我还创建了此服务:

[Unit]
Description=Pulse Audio

[Service]
Type=notify
ExecStart=pulseaudio --daemonize=no --system --realtime --log-target=journal

[Install]
WantedBy=multi-user.target

但它仍然没有运行。我可以看到两者在启动时启动,但我听不到音乐(如果我在登录后简单地运行 .sh 文件,它就可以工作)。登录后,我运行“sudo systemctl --system status audio.service”,得到以下输出:

● audio.service - Servizio Musica Showroom
     Loaded: loaded (/etc/systemd/system/audio.service; enabled; preset: enabled)
     Active: active (running) since Mon 2023-07-31 14:04:13 UTC; 9min ago
   Main PID: 1206 (audio.sh)
      Tasks: 5 (limit: 9237)
     Memory: 26.3M
        CPU: 12.027s
     CGroup: /system.slice/audio.service
             ├─1206 /bin/sh /home/user/audio.sh
             └─1207 /usr/bin/vlc -I dummy --loop --intf=dummy /home/user/musica.mp3

Jul 31 14:04:13 ubuntu audio.sh[1207]: [0000aaab0f68b4d0] main interface error: no suitable interface module
Jul 31 14:04:13 ubuntu audio.sh[1207]: [0000aaab0f596230] main libvlc error: interface "globalhotkeys,none" initializa>
Jul 31 14:04:13 ubuntu audio.sh[1207]: [0000aaab0f68b4d0] dummy interface: using the dummy interface module...
Jul 31 14:04:13 ubuntu audio.sh[1207]: ALSA lib pulse.c:242:(pulse_connect) PulseAudio: Unable to connect: Access deni>
Jul 31 14:04:13 ubuntu audio.sh[1207]: [0000aaab0f665c00] alsa audio output error: cannot open ALSA device "default": >
Jul 31 14:04:13 ubuntu audio.sh[1207]: [0000aaab0f665c00] main audio output error: Audio output failed
Jul 31 14:04:13 ubuntu audio.sh[1207]: [0000aaab0f665c00] main audio output error: The audio device "default" could no>
Jul 31 14:04:13 ubuntu audio.sh[1207]: Connection refused.
Jul 31 14:04:13 ubuntu audio.sh[1207]: [0000aaab0f665c00] main audio output error: module not functional
Jul 31 14:04:13 ubuntu audio.sh[1207]: [0000ffff7cc1e6f0] main decoder error: failed to create audio output

如果我运行“sudo systemctl --system status pulseaudio.service”

我得到以下输出:

● pulseaudio.service - Pulse Audio
     Loaded: loaded (/etc/systemd/system/pulseaudio.service; enabled; preset: enabled)
     Active: active (running) since Mon 2023-07-31 13:57:09 UTC; 17min ago
   Main PID: 686 (pulseaudio)
      Tasks: 3 (limit: 9237)
     Memory: 29.5M
        CPU: 579ms
     CGroup: /system.slice/pulseaudio.service
             └─686 pulseaudio --daemonize=no --system --realtime --log-target=journal

Jul 31 13:57:06 ubuntu pulseaudio[686]: Please read http://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/>
Jul 31 13:57:09 ubuntu pulseaudio[686]: Failed to open cookie file '/var/run/pulse/.config/pulse/cookie': No such file>
Jul 31 13:57:09 ubuntu pulseaudio[686]: Failed to load authentication key '/var/run/pulse/.config/pulse/cookie': No su>
Jul 31 13:57:09 ubuntu pulseaudio[686]: Failed to open cookie file '/var/run/pulse/.pulse-cookie': No such file or dir>
Jul 31 13:57:09 ubuntu pulseaudio[686]: Failed to load authentication key '/var/run/pulse/.pulse-cookie': No such file>
Jul 31 13:57:09 ubuntu systemd[1]: Started pulseaudio.service - Pulse Audio.
Jul 31 14:01:57 ubuntu pulseaudio[686]: Denied access to client with invalid authentication data.
Jul 31 14:01:57 ubuntu pulseaudio[686]: Denied access to client with invalid authentication data.
Jul 31 14:04:13 ubuntu pulseaudio[686]: Denied access to client with invalid authentication data.
Jul 31 14:04:13 ubuntu pulseaudio[686]: Denied access to client with invalid authentication data.

相关内容