Music that is composed specifically for use in a play, film, commercial, radio or TV program, computer game, ceremony or other such event is called incidental music. Music not written specifically for such purposes but nevertheless used in these ways can also be called incidental music.
The use of music in dramatic productions goes way back to early Greek plays, but truly significant use of musical elements did not appear until the 16th century or so. Music for the plays of Shakespeare and others continued to be written into the 19th century by composers such as Schubert, Beethoven, and Mendelssohn.
Since that time, incidental music has steadily increased in popularity and importance. In the early 20th century, strong partnerships developed between playwrights and composers, a trend set by Ramuz and Stravinsky with "A Soldier's Tale", and continued by Bertolt Brecht and Kurt Weill with "The Threepenny Opera" and other works, the operettas of Gilbert and Sullivan, and the modern musical plays and films. Indeed, the relationship of music, acting and dance in 20th century stage and screen musicals is so intimate that one finds it difficult to call the music incidental in any sense. In many cases, the music has become more familiar and appreciated than the play or movie to which it is incidental.
In today's world, audio-visual media have taken center stage in entertainment and advertising, and the production and licensing of incidental music for programs and commercials on TV and radio, and computer games has become a major industry. Remember the millions of dollars paid by Microsoft some years back to use just a few seconds of a Rolling Stones tune in the Windows introduction campaign? Indeed, we now have what might be called incidental video in the form of music videos produced as a backdrop for popular music.