Sounds like most of solutions people have put forward didn't work for OP. But for the sake of any one finding this question by google, and suffering from a similar problem that I just had here's how I fixed it.
I had set up a few screen sharing programs which did some pretty annoying stuff to the audio drivers, which required me to specify whether I wanted audio to come out of the builtin speakers or headphone jack, even after uninstalling these programs the problem still persisted.
What Fixed this
I entered the following commands in my terminal, you'll be prompted for your password.
sudo rm /Library/Preferences/Audio/*.plist
sudo killall coreaudiod
- The first one just removes the audio configuration files
- The second command just reboots the audio drivers, the files are then replaced.
This is similar like @user63463 's solution but you don't have to restart your computer :)
now pull your audio jack in and out and watch the audio source switch between builtin speakers, headphones, and whatever else like they originally did.