Diegetic music

Diegetic music or source music is a form of music in movies and dramas. It is when the audience hears the same thing the characters hear. In storytelling, it is called diegesis. Non-diegetic music is when the characters cannot hear the music. Diegetic sound can include noises of objects or voices in the story. 
Film Music.
Diegetic music is common in movies. The characters in a film hear something and the audience hears the same thing. If a character in the film turns on a CD player and listens to music and the audience hears it, this is called diegetic. In the film "Titanic", a string quartet plays music while the ship is sinking. The people on the ship hear the music and the audience hears the music. In "Apocalypse Now", helicopters are raiding a village. The leading colonel turns on a loud stereo with the music The Ride of the Valkyries by Richard Wagner. The soldiers hear this music and the audience hear it too. When Marty Mcfly plays his guitar in "Back to the Future", both the characters in the film and the viewers hear it. Marty plays music from the future. The listeners in the film do not know the music, but the music is still diegetic. 
There are variations to diegetic music. One is "metadiagetic" sound. These are sounds the characters imagine. The sounds are not heard in the surrounding reality. This is not that common in films. An example is in "Amadeus" (1984). Composer Antonio Salieri, played by F. Murray Abraham is reading music composed by Mozart and the audience hears what Salieri imagines in his head. There is no actual orchestra present in the scene playing the music. 
There is also "cross-over diegesis." This is when the music goes from diegetic to non-diegetic. "Non-diegetic" music is not heard by the audience. In "Star Wars", most of the score is "non-diegetic" orchestra work that John Williams composed. The music may describe characters or scenes like Leia's Theme or the Imperial March. However, only the audience hears this music. 
Musical Theater.
In musical theatre diegetic music has the same meaning. It is music in the narrative of the story. This is not necessarily when characters sing and are unaware. However, it is when there is a song literarily in the plot. For instance, in the "Sound of Music" the song Edelweiss is diegetic. Captain von Trapp is performing it in the story for others in the story.