about music detection

I developing an app. In that app music player is there and added some functions like to open YouTube and music.


When I open the YouTube we will play some videos and our developing app is running at background.


In background app we want to detect any music are videos are playing and detect music and videos are stoped.