At school there are sometimes when the teacher shows videos to the class that have music in them. Is it not allowed for me to sit with them while they watch it?
Sometimes also in class the teacher might mention words that contain shirk but almost immediately he switches to another topic am I not allowed to sit with them also?
This is from my understanding of the verse in the Quran 4:140 "...that when you hear the revelations of Allah rejected and mocked, you are not to sit with them until they turn to some other theme; for if you do so you will be like them..."
In the name of Allah, The All Merciful.
Islam will only charge someone when the action is performed intentionally and personally the person himself or herself. In the case you described, you were not the one who turned on the radio with the intention to listen to music. The Prophet (swa) said: “Verily all deeds are upon the niah (intention) and every person is up to what he intends to do”.
Regarding your second question, again, you are not responsible if someone commits shirk or say words of shirk. You should leave this place if you hear someone mocking or making fun of your deen (i.e. making fun of the ayats of Allah or our Prophet (swa)). You cannot sit with them.
Allah knows best.