HDMI is not working in Ubuntu 16.04
Redirecting Audio can become quite difficult in some cases.
For example my firefox never liked to play audio thru hdmi while all other software did. Since i use pulse audio, it works like charm; check the end of this answer.
I am using Lubuntu 16.04. It might be different from your desktop, but automatic switching never occured by default. I always had to direct the audio stream manually. In general you have at least two audio-outputs: One analoge audiojack and one digital hdmi, in general on different audio-cards.
The hard way:
First i had to get an overview on the audiocards installed on my htpc (ati motherboard with onboard graphics and onboard cpu):
aplay -l **** List of PLAYBACK Hardware Devices **** card 0: Generic [HD-Audio Generic], device 3: HDMI 0 [HDMI 0] Subdevices: 1/1 Subdevice #0: subdevice #0 card 1: SB [HDA ATI SB], device 0: ALC887-VD Analog [ALC887-VD Analog] Subdevices: 1/1 Subdevice #0: subdevice #0 card 1: SB [HDA ATI SB], device 3: ALC887-VD Digital [ALC887-VD Digital] Subdevices: 1/1 Subdevice #0: subdevice #0
and all the possible audio-streaming channels i could route the sound:
aplay -L null Discard all samples (playback) or generate zero samples (capture) pulse PulseAudio Sound Server hdmi:CARD=Generic,DEV=0 HD-Audio Generic, HDMI 0 HDMI Audio Output dmix:CARD=Generic,DEV=3 HD-Audio Generic, HDMI 0 Direct sample mixing device dsnoop:CARD=Generic,DEV=3 HD-Audio Generic, HDMI 0 Direct sample snooping device hw:CARD=Generic,DEV=3 HD-Audio Generic, HDMI 0 Direct hardware device without any conversions plughw:CARD=Generic,DEV=3 HD-Audio Generic, HDMI 0 Hardware device with all software conversions default:CARD=SB HDA ATI SB, ALC887-VD Analog Default Audio Device sysdefault:CARD=SB HDA ATI SB, ALC887-VD Analog Default Audio Device front:CARD=SB,DEV=0 HDA ATI SB, ALC887-VD Analog Front speakers surround21:CARD=SB,DEV=0 HDA ATI SB, ALC887-VD Analog 2.1 Surround output to Front and Subwoofer speakers surround40:CARD=SB,DEV=0 HDA ATI SB, ALC887-VD Analog 4.0 Surround output to Front and Rear speakers surround41:CARD=SB,DEV=0 HDA ATI SB, ALC887-VD Analog 4.1 Surround output to Front, Rear and Subwoofer speakers surround50:CARD=SB,DEV=0 HDA ATI SB, ALC887-VD Analog 5.0 Surround output to Front, Center and Rear speakers surround51:CARD=SB,DEV=0 HDA ATI SB, ALC887-VD Analog 5.1 Surround output to Front, Center, Rear and Subwoofer speakers surround71:CARD=SB,DEV=0 HDA ATI SB, ALC887-VD Analog 7.1 Surround output to Front, Center, Side, Rear and Woofer speakers hdmi:CARD=SB,DEV=0 HDA ATI SB, ALC887-VD Digital HDMI Audio Output dmix:CARD=SB,DEV=0 HDA ATI SB, ALC887-VD Analog Direct sample mixing device dmix:CARD=SB,DEV=3 HDA ATI SB, ALC887-VD Digital Direct sample mixing device dsnoop:CARD=SB,DEV=0 HDA ATI SB, ALC887-VD Analog Direct sample snooping device dsnoop:CARD=SB,DEV=3 HDA ATI SB, ALC887-VD Digital Direct sample snooping device hw:CARD=SB,DEV=0 HDA ATI SB, ALC887-VD Analog Direct hardware device without any conversions hw:CARD=SB,DEV=3 HDA ATI SB, ALC887-VD Digital Direct hardware device without any conversions plughw:CARD=SB,DEV=0 HDA ATI SB, ALC887-VD Analog Hardware device with all software conversions plughw:CARD=SB,DEV=3 HDA ATI SB, ALC887-VD Digital Hardware device with all software conversions
Now I needed to find out, which of these channels is used by my hdmi cable. Therefor I needed an audioplayer that allowed me to route the audio manually to test each of the above channels, one by one, until i found out, which of them belongs to my hdmi. With a GUI vlc and especially audacious come in handy. On CLI basis we could also use aplay, but i am not familiar with that.
Now, after having found out, which channel belongs to my hdmi cable, it was card 0, device 3, i needed to create a file in my homefolder .asoundrc Asound Wiki with the information what card, and what device to use.
pcm.snd_card { type hw card 0 device 3 } ctl.snd_card { type hw card 0 device 3 }
Also i needed to run 'alsamixer'. With F6 i did select my soundcard and had to navigate with the arrow keys to the S/PDIF and activate (unmute) it with the M key.
After a reboot audio thru hdmi worked, but firefox remained unwilling to play audio via hdmi.
Long story short, now i use PulseAudio and i am very happy with it.
The easy way
Since i installed PulseAudio the handling of the audio devices has become very easy.
I would suggest you to install:
sudo apt-get install gstreamer1.0-pulseaudio pavucontrol pulseaudio-module-x11
pavucontrol
is a comfortable GUI to (re)direct your audio-streams to the device/channel you want.
I hope this helps you to find a solution.
I was having this exact same problem a few days ago. Prior to this happening, I had installed KDE desktop and was just getting used to the new DE when all of a sudden the next day my HDMI stops working. Before switching to KDE, I had been using Budgie desktop and HDMI was working.
I tried everything but nothing worked. I spent almost an entire day trying to get this to work, but all to no avail.
Yesterday, finally got tired of KDE because of some issues (kWallet and kOrganizer were being difficult) that just affected the usability of the DE. After uninstalling the DE, I reboot my machine and like magic, my external monitor sprang to life.
I was shocked to say the least, but I hope that helps anyone.
tldr; If you have recently installed a new DE, try removing it!!