Praise be to Allaah.
There is a difference between the one who listens to music and the one who hears it. The one who listens to songs hears them deliberately, wants to hear them and enjoys that, whereas the one who only hears the sound that reaches him, without wanting or intending to do so, such as when riding in an airplane or a bus in which there is music, or who goes to the marketplace and hears that from some stores without wanting or intending to listen to it. There is a difference between the latter and the one who sits down to listen to and enjoy this haraam thing.
Hence Shaykh al-Islam (Ibn Taymiyah) said: The command and the prohibition have to do with listening. Merely hearing something is like seeing; it has to do with the intention behind seeing, not what happens without a person choosing it…. The same applies to committing sin through the five senses of hearing, sight, smell, taste and touch; the commands and prohibitions are connected to what a person intends and does, but whatever happens without him choosing it, there is no command or prohibition with regard to that.
(Majmoo’ al-Fataawa, part 5, p. 566)
One has to denounce that evil as much as possible, but if he cannot do that, then he should denounce it in his heart. One of the things implied by denouncing it in one’s heart is not remaining in a gathering or a place where that evil is happening, if one is able to leave.
With regard to listening to it, one must strive against that as much as possible and seek refuge with Allaah from the Shaytaan, and remember Allaah. Then Allaah will take that away from you. If that makes your heart attracted to it, then you should keep away from those parts of the school. If it will not cause you a lot of trouble to miss some of those classes in which these things happen then you should not attend them. You have to remember that Allaah is always watching and fear Him, for whoever fears Allaah, Allaah will give him a way out. Allaah says (interpretation of the meaning):
“And whosoever fears Allaah and keeps his duty to Him, He will make a way for him to get out (from every difficulty)”
And Allaah is the Source of strength.