0

I am working on an android app that does audio routing to speaker/wired headset. Given that some audio is playing, is it possible to programmatically detect whether the audio playing is a song (media clip) or if it is voice from an established call, using java?

EDIT: I realized that I can solve my problem easily because, when I receive or make a call, only that voice audio can be heard. Is there any function which determines if I am on a call or not?

SoulRayder
  • 5,072
  • 6
  • 47
  • 93
  • if you are recording call and if you want distinguish between them then it is easy to recognize with the saved file extension – praveen Jan 08 '14 at 09:34
  • No No.. I am listening to either a song or I am receiving a call. Now is it possible to programmatically find out whether the sound I am hearing is a song or is it voice from the call? – SoulRayder Jan 08 '14 at 09:36

1 Answers1

1

Try this function:

public boolean isOnCall(Context context){
   AudioManager manager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE);
   if(manager.getMode()==AudioManager.MODE_IN_CALL){
       return true;
   }
   else{
       return false;
   }
}

Add permission in manifest, too.

<uses-permission android:name="android.permission.READ_PHONE_STATE" />  

Hope this helps.

MysticMagicϡ
  • 28,593
  • 16
  • 73
  • 124