Speaker and Headphones on Microcomputer
The LM4863 is a dual amp with headphone functionality. Its datasheet shows exactly how to connect speakers and a headphone jack to implement the application you describe.