There are three elements that need to work together in order to make sound work properly in your computer. The software has to send the correct information, the sound card or controller needs to take that sound and send it to hardware, which then must play it. The sound device, the sound hardware such as speakers and output jacks, and the software all need to be working and configured properly to make sound play through your computer. If any of these aspects are not set correctly, or are malfunctioning, the sound will not work properly all the time.
Make sure that your software is set to be sending sound out to the speakers. This is the most common reason that sound does not work. On a Mac, go into the system preferences, and in Windows into the control panel. Go to the sound settings. Make sure that the output device selected is the one that you want to play your sound through, and that the volume is turned up and not muted. Also, always test sound in another program, other than the one you noticed the problem in, to make sure that it is not just a program-specific sound problem.
Update all of the software on your computer, especially the sound drivers. Updating the media player you are using and the program that you cannot hear is also very important. Follow all the instructions after you have updated all the requisite software and restart the machine.
Make sure that your sound card is being recognized by the machine. Go into your hardware manager and make sure that your on-board sound device or sound card is recognized by the system. If it is, and all the updates have been applied, there is likely another problem.
Test your sound hardware. Try any external headphones or speakers on another computer or audio device to make sure that they work. Next, try other headphones and speakers in the port that has no sound. Make sure that powered speakers have power, and that any external volume controls are turned up. If you suspect a problem with internal speakers in a laptop, it is best to take the computer to a professional to be assessed. Don't work inside a laptop unless you have experience in taking them apart and aren't afraid of a voided warranty.
Always try to isolate where the problem is. Sound problems are generally easy to fix once you narrow down the reason why the sound isn't working.