0

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 !

Nachding
  • 465
  • 2
  • 10
  • 20
  • My guess would be that there is no generic way to do this. 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. – Sildoreth Mar 30 '15 at 17:05
  • Thank you ! What is the name of default application to listen to music on Android please ? – Nachding Mar 30 '15 at 17:19
  • It probably depends on the device. But based on a cursory web search and a quick look at my Android phone, it looks like [Google Play Music](https://play.google.com/store/apps/details?id=com.google.android.music) is the default. – Sildoreth Mar 30 '15 at 17:26
  • Can I ask you one last question ? how to simply detect when an application is in use ? I have searched on internet but I still have no idea... – Nachding Mar 31 '15 at 08:03

2 Answers2

0

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

Kerbstomp
  • 164
  • 1
  • 1
  • 11
0

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.

Community
  • 1
  • 1
Sildoreth
  • 1,883
  • 1
  • 25
  • 38