How can I specify which programs play sound through headphones and which ones play through speakers?

Click on the sound indicator and go to settings. Then on the application tab there is a per application setting for output and input device. It it doesn't have it there then you can looking in pavucontrol (you may have to install it). It's a bit more complicated to use but works quite well.