Some games do not have a set time limit, or the time limit is so long that it's unrealistic to create one song to encompass the entire level. In these cases it is important for the musical composers to create a song that works as a loop. The song has to begin and end the same way. Not only does this effectively fill up a level of any length but also because of the content looping helps get the song in the gamers head making it memerable. The loop can have drawbacks if the loop is too short. It turns from catchy, fun, and classic, into annoying and irritating.
Some songs are timed for specific events. For example in Halo you go around with barely a note played but once a battle starts the music comes in. This makes the song not only stand out against the stark silence that came before but also sets the mood for the battle. Music can cue the player how to play, and the timed song does this the best. Having a song fade in or out and change depending on the atmosphere of the game can really inhance the mood. The oinly problem with the timed song is what to put in between one song and another, since they don't always mesh together.
Now this is a very new and experimental type of gameplay that isn't used that much, most likely because it is difficult to pull off with great success. Now some rhythm instrument games like Guitar Hero, or Rock Band fall into this category. Those games have music as their main focus and it is fairly easy to set gameplay around it, press the buttons at the right time to make the music. This is not so much interactive music as it is a timing excerise. It's a lot of fun and gives the player the idea that he/she is actually playing the music. This is the most common type of interactive music.
The other form of interactive music does not require picture perfect timing and is a lot harder to pull off successfully. In these games the music goes along with the player no matter when the buttons are hit. Unlike the previous games the music always sounds different. Here are some games to give you a better idea what I am talking about.
Sound FX is probably the biggest challange for video game composers. Every time your character shoots, jumps, hits an enemie, dies, and many other things, a sound FX usually occurs. These sounds have to compliment the music in the game. While they do not directly effect the music they are still played on top of it. It would be jarring to hear a sound that does not go along with the overall score. This is why when Mario jumps it sounds different from when Sonic jumps, each sound effect has to go along with the music in their repective games. You are in control of the hero and its up to you how you play with it, the sound FX designer has to make sure every sound you can possibly make will fit into the musical score of the game.
Everything I mentioned before is an answer for"how" video game music is used, but an equally important aspect is the "why." I touched on this aspect before in my intro blog post but I think that it is such an important part of the video game artform I have to also expand on this. If the composers have done their job properly not only will the music fit into the game thematically, and go together with the sound FX but also relay an emotion to the player. If you are going to have a level in a forest, the music should be light and fun, connecting the player to the mood of nature. When the player is in a lava level, light fun music won't cut it, you need a faster paced tune. If you are in a dark dungeon the music should have a dark or "echo" sound to it further bringing the player into the environment. The music should connect to the player by bringing him/her into the environment as well as letting the player know how much action to expect on the screen. So if you are in a light easy forest level but you are at the boss and the action has picked up the music should not stay all light and slow, it should pick up a bit while still maintaining the feel of the level. I will leave off this post with some examples of music effecting mood, and gameplay.
Shadow of the Colossus Boss fights
Then game is extremely silent for the most part. The silence ends however, when you finally meet up with a Colossus. The music stand out against the stark silence of the rest of the game, and gets the player ready for a battle.
Sonic First level