I have a hotfix, doesn't solve the core issue, but treats the symptoms so to speak (Automatically sets the 'Speaker' channel volume to 100% again everytime headphones are plugged in). On my end, the 'Speaker' channel does not actually need to be unmuted, but it's volume needs to be set to 100 for me to get normal sound. The command I use to do this is
amixer -c 0 set Speaker 100
For those that really do need to unmute the channel it would be:
amixer -c 0 set speaker 100 unmute
First off you need to test this command, if it doesn't do anything, the '-c 0' value is most likely wrong (-c is for card) you can run aplay -l
to get a list of all sound devices, you need to find the corresponding 'card number' for your soundcard. (It will normally be 0, sometimes 1, rarely anything else)
Once you confirm that the command is doing what it's supposed to, create the script in: /home/user/scripts/headphonefix.sh
#!/bin/bash
sleep 0.5 && amixer -c 0 set Speaker 100
Where '/home/user' is the path to your home folder. (You can use any path you want though, it's just a suggestion).
Next make the script executable with
chmod +x /home/user/scripts/headphonefix.sh
Now we're halfway done.
I'm not on ubuntu myself (I'm using manjaro) but this 'fix' requires the acpid service to be running (I think it's enabled by default on ubuntu, on arch it's systemctl enable acpid to start it on every boot.)
To check if the acpid service is running, run acpi_listen. If you get a socket error the service is not running, if you just get a blank output, you're golden.
With acpi_listen running plug in your headphones to get the event for it, for me it was: jack/headphone HEADPHONE plug
Now with that information, we can create this file (use sudo): /etc/acpi/events/headphones
Make it's contents look something like this:
event=jack/headphone HEADPHONE plug
action=/home/user/scripts/headphonefix.sh
Where /home/user/scripts/headphonefix.sh is the path to the script we created earlier.
Now to confirm it's all working, we need to restart acpid either by rebooting or running this command:
Ubuntu: sudo service acpid restart
Arch/Manjaro: systemctl restart acpid
Then unplug your headphones then plug them back in, and voila, everything should be 'working' now.
It's not a perfect solution, since it just makes alsa set the speaker channel's volume to 100% again everytime a headset is plugged in, rather than addressing the underlying issue of why this is happening under the hood. But if you just want shit to work like normal, this'll do the trick.
(Note: You will also want to run this script automatically on startup in case your headphones are plugged in on bootup)
sudo apt-get install pavucontrol
. I find it more user friendly than Alsamixer.