MAT
MAT

Reputation: 1

When you plug in a HDMI after booting of a Raspberry Pi 4, you get the display but not the audio

When HDMI cable is pluggwd in at the boot time, the Rasp Pi 4 display comes up normally and audio plays. (One can check by right clicking on the audio icon on the menu bar, to see the device profile in which HDMI is selected by default.)

Now even if you remove the HDMI cable and then replug it in, you will get back the normal display and the audio

However, if you boot up the Rasp Pi and plug in the HDMI cable later on, the display will come up but the audio will be missing. Right clicking on the audio icon of the Menu bar will reveal that HDMI is itself missing in the device profile.

I have tried out all permutation/ combinatioms of HDMI in the /boot/config.txt, but that doesn't help.

My Pi is normally supposed to be used as a Hotspot, but as an option, one can plug in a HDMI monitor anytime. Rebooting shouldn't be required to get the audio.

Note that there is, of course, no problem if there was a switched-off HDMI monitor connected at the boot time, Whenever one switches the monitor on, the display and the audio will be back.

The missing audio problem comes only when you connecr a HDMI monitor, later on.

Upvotes: -1

Views: 1252

Answers (1)

MAT
MAT

Reputation: 1

After extensive trying out with the help from the raspberry pi forum (https://forums.raspberrypi.com/viewtopic.php?t=343523 ) following is the solution which works well.

In /etc/udev/rules.d/99-HDMICallback.sh keep this rule

KERNEL=="card?", SUBSYSTEM=="drm", ACTION=="change", RUN+="/home/pi/HDMICallback.sh"

In HDMICallback.sh keep this shell code

HDMIDetect(){
    systemctl --user stop pulseaudio.service  
    systemctl --user stop pulseaudio.socket     
    pulseaudio --start
    touch /tmp/HDMI.pr
}
export -f HDMIDetect

[ ! -f /tmp/HDMI.pr ] && [ "$(cat /sys/class/drm/card?-HDMI-A-1/status)" == "connected" ] && su pi -c "bash -c HDMIDetect"

Essentially the pulseaudio has to be stopped and then restarted, when the HDMI plugin triggers the HDMICalback.sh. Once the pulseaudio has been started, then the same doesn't have to be done, on subsequent HDMI plugouts and plugins - hence the /tmp/HDMI.pr variable.

Unlike a PC, Raspberry PI can be started without a HDMI Monitor attached, perhaps for serving in a headless way or with a hnotspot. At any point an HDMI monitor can be attached with the display and audio coming up immediately.

Upvotes: 0

Related Questions