2

Is there a way to know if the telephone is playing anything? for example a ringtone.

My phone doesn't work properly and I sometimes get a call without a ringtone. I mean, I can see the incoming call screen but nothing is heard (of course it is not in silence). It happens sometimes.

So I programmed something to detect incoming calls (a receiver) and play the default ringtone. It works pretty well when my phone fails, because I force it by playing it again.

The problem comes when my phone works! because in that case you can hear both at the same time (phone's and mine) and sounds terrible!

So I need to do one thing of these two:

-Either detect that the phone worked well (it is ringing) so I don't have to play anything. -Or stop any current ringing (if any) and play it myself always.

Any help?

P.S.: I tried isMusicActive() and it doesn't work for the ringing.

Ton
  • 9,235
  • 15
  • 59
  • 103
  • Similar question, possible dupe: [How do you check if music is playing from a broadcast receiver?](http://stackoverflow.com/q/7323915/404469). It utilizes the `AudioManager.isMusicActive()` method just as the current answers point out. – gary Jun 30 '12 at 19:14
  • Ah, now that you explained the context, I think you may want to search http://android.stackexchange.com/ and post a question there. Not as a developer, but as a user. – gary Jun 30 '12 at 20:12

2 Answers2

0

You could try using the isMusicActive() method in AudioManager. I'm quite sure that it'll work system wide, but if you try it and it doesn't, do post back here.

Raghav Sood
  • 81,899
  • 22
  • 187
  • 195
0

This page gives a great description of how to manage audio focus. You could implement onAudioFocusedChangedListener to get constant updates on what is playing.

And even the isMusicActive() method may also be helpful, as @raghav points out.

udiboy1209
  • 1,472
  • 1
  • 15
  • 33