无法让声音在命名空间中工作

无法让声音在命名空间中工作

我正在尝试让声音在 Linux 网络命名空间中工作

 (+) Audio --aid=1 (mp3 2ch 44100Hz)
ALSA lib pcm_dmix.c:1090:(snd_pcm_dmix_open) unable to open slave
[ao/alsa] Playback open error: No such file or directory
[ao/oss] Can't open audio device /dev/dsp: No such file or directory
connect(2) call to /dev/shm/jack-1000/default/jack_0 failed (err=No such file or directory)
attempt to connect to server failed
[ao/jack] cannot open server
ALSA lib pcm_dmix.c:1090:(snd_pcm_dmix_open) unable to open slave
couldn't open play stream: No such file or directory
[ao/sndio] can't open sndio default
[ao] Failed to initialize audio driver 'sndio'
Could not open/initialize audio device -> no sound.
Audio: no audio


Exiting... (Errors when loading file)

当尝试使用 mpv 播放 mp3 时,出现上述错误。

我尝试运行以下命令,但没有帮助

HOME='/home/dewi' PULSE_SERVER=/run/user/$(id -u dewi)/pulse/native PULSE_COOKIE=/home/dewi/.config/pulse/cookie
XDG_RUNTIME_DIR="/run/user/1000"

请帮助?

答案1

你必须出口这些变量:

HOME='/home/dewi'
PULSE_SERVER=/run/user/$(id -u dewi)/pulse/native
PULSE_COOKIE=/home/dewi/.config/pulse/cookie
XDG_RUNTIME_DIR="/run/user/1000"

export HOME PULSE_SERVER PULSE_COOKIE XDG_RUNTIME_DIR

您可以将这些变量传递给 sudo,如下所示:

ip netns exec somens sudo HOME='/home/dewi' PULSE_SERVER=/run/user/$(id -u dewi)/pulse/native PULSE_COOKIE=/home/dewi/.config/pulse/cookie XDG_RUNTIME_DIR="/run/user/1000" -u dewi -- /bin/bash

这样做更好,因为您不必在 shell 上手动设置和导出这些变量,如果您想编写 shell 脚本,这会很好。

相关内容