I program in recent years to Android and I wonder something : How to detect when user is listening to music with his device ? I really do not know where to start :(
Thank you for your help !
I program in recent years to Android and I wonder something : How to detect when user is listening to music with his device ? I really do not know where to start :(
Thank you for your help !
Use AudioManager to check this..it has a special function to figure this out for you but I'll let you find it. Documentation is your best friend :D http://developer.android.com/reference/android/media/AudioManager.html
Since I'm commenting so much on this question, I'll just condense my comments into an answer...
My guess would be that there is no generic way to do exactly what you're asking. The user could use any number of applications to listen to music. The best you could probably do is to pick a few media players that you want to recognize and handle those specifically. Though, you'd probably only be able to tell whether the application is running, not whether it's currently playing music.
Disclaimer: this assessment is based on an overall knowledge of programming, not on a deep knowledge of Android. Perhaps seasoned Android programmers know a few tricks.
I'm not sure what the default player is on a typical Android device. It probably depends on the device. But based on a cursory web search and a quick look at my Android phone, it looks like the default is Google Play Music.
As for checking whether an application is currently running (and possibly whether it's playing music), I recommend these other stackoverflow posts as a starting point.