So basically we take the sensor value and judge whether the person is still wearing the headphone or no if yes then we going and if not or as soon he has removed the headphone we trigger the processes hitting sound card and try to pause them all and as soon as the one worn the headphone again we start ( play ) the audio or video. 

We have one more feature to keep checking the ambient noise and according to increase in level of the noise we increase the volume of the media playing and as soon the volume is back to original level we slows the volume down.