문제

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?

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top