Ubuntu 10.10 is somehow not really up-to-date which makes it a bit hard to confirm the default pulseaudio installation there. However it may be worth to see if you have the module-switch-on-port-available loaded.
In case it is there, then try to disable it by commenting out (#
) the following line in your /etc/pulse/default.pa
:
# load-module module-switch-on-port-available
After the next restart of the pulseaudio server (e.g. with pulseaudio -k
in a terminal) we should no longer switch to a different audio port when this becomes available (e.g. by plugging in your HDMI cable).
For the benefit of people who stumble upon this question - Salem's solution almost worked for me in 13.04, I ended up gathering bits and pieces from all around the web, I think the deal breaker for me was the lack of the environment variable PULSE_SERVER
Here is my full solution, which is basically repeating Salem's solution with the few missing pieces. I also redid it as a shell script (despite my love for Python) because I was afraid at first that my Python script is running into import path issues:
(same as Salem's answer) Create a file /etc/udev/rules.d/hdmi_sound.rules
as root with the content:
SUBSYSTEM=="drm", ACTION=="change", RUN+="/usr/local/bin/hdmi_sound_toggle"
Create a file /usr/local/bin/hdmi_sound_toggle
as root with the content:
#!/bin/sh
USER_NAME=`who | grep "(:0)" | cut -f 1 -d ' '`
USER_ID=`id -u $USER_NAME`
HDMI_STATUS=`cat /sys/class/drm/card0/*HDMI*/status`
export PULSE_SERVER="unix:/run/user/"$USER_ID"/pulse/native"
if [ $HDMI_STATUS = "connected" ]
then
sudo -u $USER_NAME pactl --server $PULSE_SERVER set-card-profile 0 output:hdmi-stereo+input:analog-stereo
else
sudo -u $USER_NAME pactl --server $PULSE_SERVER set-card-profile 0 output:analog-stereo+input:analog-stereo
fi
Then make it executable with chmod 0755 /usr/local/bin/hdmi_sound_toggle
I tried to make this script as generic as possible, but you still might need to change some lines, such as the HDMI_STATUS file path or the profiles used. You can see a list of profiles by running pactl list cards
and looking under Profiles.
Note that the script failed for me when I removed the keyword "export" when setting PULSE_SERVER, I think pactl is looking for the env variable
Don't forget to reload your udev rules: sudo udevadm control --reload-rules
Update this script is updated for 14.04. Before that, you would use USER_NAME instead of USER_ID everywhere
Best Answer
I follow the below workaround whenever I connect laptop to a TV:
Run the below command on a console (It worked without
sudo
)Open Sound settings, you should see "HDMI/Display Port" entry under Output tab.