我试图让我的笔记本电脑在插入音频时将音频切换为HDMI,并在移除音频时将音频切换回标准模拟。
我设置了一个udev规则来触发脚本来执行切换,但是我无法使它正常工作:
- 看来,直到我在“声音设置”中选择了HDMI音频输出,才将其识别为可用的接收器,而且一旦选择了HDMI音频输出,就不再列出模拟输出。
见下面:
# HDMI plugged in, not selected in Sound settings.
$ pactl list short sinks
5 alsa_output.pci-0000_00_1b.0.analog-stereo module-alsa-card.c s16le 2ch 44100Hz SUSPENDED
kingamajick@kingamajick-laptop: ~
# HDMI selected in sound settings
$ pactl list short sinks
7 alsa_output.pci-0000_00_1b.0.hdmi-stereo module-alsa-card.c s16le 2ch 48000Hz SUSPENDED
kingamajick@kingamajick-laptop: ~
# HDMI removed
$ pactl list short sinks
9 alsa_output.pci-0000_00_1b.0.analog-stereo module-alsa-card.c s16le 2ch 48000Hz SUSPENDED
我正在使用的脚本切换输出如下:
#!/bin/bash
HDMI_STATUS=`cat /sys/class/drm/card0/*HDMI*/status`
INPUTS=($(pacmd list-sink-inputs | grep index | awk '{print $2}'))
if [ $HDMI_STATUS = "connected" ]
then
pactl set-default-sink alsa_output.pci-0000_00_1b.0.hdmi-stereo
for i in ${INPUTS[*]}; do pacmd move-sink-input $i alsa_output.pci-0000_00_1b.0.hdmi-stereo &> /dev/null; done
else
pactl set-default-sink alsa_output.pci-0000_00_1b.0.analog-stereo
for i in ${INPUTS[*]}; do pacmd move-sink-input $i alsa_output.pci-0000_00_1b.0.analog-stereo &> /dev/null; done-server $PULSE_SERVER set-card-profile 0 output:analog-stereo+input:analog-stereo
fi
在声音设置中选择HDMI之前,触发脚本时,脚本会提示没有此类沉陷。