Welcome to Ask Ubuntu. Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
–
PeachySep 8 '12 at 12:42

I now get no sound in my ubuntu 14.04!! This is the first time I have ever had problems with sound what is going on!!
–
uzi3kJun 22 '14 at 10:56

I have had this problem on my Asus K55vm laptop since 12.04. Although your solution does work, in laptops it will cause the sound to be transmitted by both the plugged headphones and the speakers. To make them work properly and only have sound come out of the headphones when plugged in or the speakers when headphones are not plugged in:

This works FOR ME BUT: keep in mind that when you plug in your headphones their volume will be the volume they were the last time and when you unplug them the speakers volume will be the volume it was before you plugged in the headphones.

I hope this can also help someone with the same problem as me and thank you very much bozbezbozzel! Without you I would not have made it. :)

If you are running close to a vanilla install of Ubuntu 12.04LTS, try sudo apt-get update and sudo apt-get update --fix-missing. Now I know those are very novice answers, but it may just work. My last suggestion is to go to this answer: When I plug in headphones, my speakers mute, but nothing comes from the headphones which is loosely related to the issue you are having. If this doesn't help, try going to the audio options in system settings and make sure you have the correct output selected.

Thanks for the quit answer and this does help a bit, but not as expected. I identified the PIN and enabled "out", but sound appears only for a second and goes silent again
–
user1228633May 2 '13 at 16:49

Thank you for your help, it needed a reboot and some try and error, but now it works. The only thing, which isn't perfect now is, that settings->sound cannot switch between headphones/speakers. But this is okay, since I exported 2 scrips for enabling / disabling headphones / speakers :)
–
user1228633May 2 '13 at 22:02

I've got an HP Pavilion dv6 with beats audio, and I had the exact same problem. Alsamixer muted the 'Speaker' volume when I plugged my headphones in, and apparently, that is the volume the headphones use. I found the following workaround:

Now, do the same with usr/share/pulseaudio/alsa-mixer/paths/analog-output-headphones-2.conf
and reboot. Now your headphones should work. However, when you unplug them the sound from your internal speakers will be at the same volume your headphones were at. So while this does not make the audio work as well as before, at least it doesn't mute your headphones all the time.

EDIT: Only one of the headphone jacks (the one at the front) is working for me, even though I changed headphones-2 as well. No idea why.