27

This question might seem to be a repetition of the questions such as following:
How to play an audio file on a voice call in android
Background Audio for a Call in Progress - Possible?

The answers of these questions suggests that it is not possible to play a pre-recorded audio on a voice call in android. I want to know why it is not possible? What is the limitation (hardware/software)? Is it really a limitation or done purposely? Can we alter the source code of android to make it possible?

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Falak
  • 451
  • 1
  • 4
  • 11
  • 1
    When I receive incoming call, I can listen when another application create sounds from Notification. – Tapa Save Jan 13 '15 at 08:51
  • It is not about to listen a recording on the same end, but to play something for remote party. – Nasir Iqbal Jan 13 '15 at 11:27
  • When I use MXPlayer to watch videos and someone call my phone , When I answer , the video will pause for 1 second then It is playing again , So it has sound playback on the voice calls maybe. – Morteza Soleimani Jan 17 '15 at 08:58

5 Answers5

20

I think this is a limitation, imposed for security reasons and restricted at the OS level.

Let's analyze the security threat, first of all. If you were able to play custom audio files to the callee, a whole world of cons opens up: you could trick customer supports, you could pretend to be someone else, you could give unauthorized purchase confirmations, and so on. For this reason, neither Android nor iOS allows this functionality.

On Android, you won't be able to do so in a programmatic way, simply because the current APIs won't allow you to do so. It is stated in the official documentation as well, as pointed out here. If you dig into the source code, you can probably enable this feature by accessing the microphone output during a phone call, but that would require running your custom version of Android. A good starting point would be the AudioTrack source, available here.


EDIT: a good example of an audio mod involves enabling the Nexus 5 earpiece as a second loudspeaker (requires root). Can be found here.

Community
  • 1
  • 1
Sebastiano
  • 12,289
  • 6
  • 47
  • 80
  • Regarding security we already have thought all of this, Actually every modern way of communication is itself a security threat, see our blog http://www.ictinnovations.com/growing-use-of-voip-requires-additional-anti-terrorism-measures – Nasir Iqbal Jan 13 '15 at 10:59
  • Well, OK, but that's the reason why this limitation is being posed. – Sebastiano Jan 13 '15 at 11:02
  • Actually I want to know that where this restriction lies. If it is software related, then why nobody had succeeded to overcome it (remember android is open source) – Nasir Iqbal Jan 13 '15 at 11:24
  • It's not that, somewhere in the code, you can de-comment a couple of lines and enable this feature. It's simply not there. There is no audio output destination that goes to the phone line out, so you would have to rewrite part of the Android framework (at the C++ level) in order to add this audio output and achieve what you want. – Sebastiano Jan 14 '15 at 10:09
  • 3
    I can't believe it's *security*. I have looked at the innards of a $79 Samsung phone. I'm pretty sure I could connect the mic to a $20 digital recorder with two wires and *perhaps* a couple resistors, without touching the software at all, and have any audio I wanted play back at the flick of a switch. Actually I could enclose the phone in a large anechoic Styrofoam box with a digital recorder and do without touching *either* the software or the hardware in any way. I admit that the only application of such a feature that I can see are prank apps, though :-) – LSerni Jan 16 '15 at 23:55
16

After a thorough research, what I have come to know is that there are more than one limitations/hurdles to make it possible. These limitations/hurdles are at three different levels.

First limitation is at API level, because there is no high-level API to play sound files in the conversation audio during a call as mentioned in Android official documentation.

Second limitation is at Radio Interface Layer (RIL). RIL passes on complete control of the call to Radio Daemon (rild) of the Linux library which then further passes the control to the vendor RIL. That means we cannot manipulate voice call in android source code.

Even if we are able to remove these two limitations, we may still not be able to play audio file to an ongoing voice call. Because there is a third limitation. Every vendor has their own library of RIL that communicates with Radio Daemon (rild). This requires that vendor RIL to be open source which is not actually. Hardware vendors do not usually make their device drivers code available.

Detail discussion on this topic is present at this link.

Falak
  • 451
  • 1
  • 4
  • 11
5

This is software related due to the prioritization of audio routing in Android. Take a look into the CallManager where you can dig into the method setAudioMode(). After the audio mode was set to MODE_IN_COMMUNICATION the following code is called

audioManager.requestAudioFocusForCall(AudioManager.STREAM_VOICE_CALL,
                        AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);

From this point on the telephony service has the highest priority and won't let any other audio play in parallel.

clash
  • 532
  • 4
  • 17
0

Note: You can play back the audio data only to the standard output device. Currently, that is the mobile device speaker or a Bluetooth headset. You cannot play sound files in the conversation audio during a call.

See official link http://developer.android.com/guide/topics/media/mediaplayer.html

Akash
  • 681
  • 3
  • 17
0

By implementing the AudioManager.OnAudioFocusChangeListener you can get the state of the audiomanager. so by this if any music is playing in the background you can get the AudioManager states(playing and pausing is completely in developer hands) similarly......

Some of the native music players in android device where handling this, they restrict the music when call is in TelephonyManager.EXTRA_STATE_OFFHOOK.so this scenario is also completely in developer hand (whether to handle or not) if he is not handling both will play parallel y

KomalG
  • 808
  • 9
  • 18