Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to play audio file when call starts?

I am initiating a voice call from my application. Now i want that when the user on the other side picks up the call, i want to play a recorded audio file.

How to go about this? Please help!

like image 376
Shafi Avatar asked Sep 21 '11 06:09

Shafi


People also ask

How can I play audio during call?

Turn on the hands free function of your phone. Create a media player, set the media source, set the volume to 1.0f (highest) and call player. start() . If the microphone and speakers on the phone are of reasonable quality, the other party to the call will hear the music.

How do I play an audio file?

Open File Manager and navigate to the folder where the audio file is located. Drag the audio file icon from File Manager and drop it on the Audio main window. The Selected file is opened. If Automatically play audio file on Open is selected in the Options-Play dialog box, the audio file starts playing.

How do I open audio files on Android?

To play audio or video files in Android, the Android multimedia framework includes the support of MediaPlayer APIs. So, by using MediaPlayer APIs, you can play audio/video files from your Android filesystem or play files from your Application's resource file or even you can stream audio/video files just like Spotify.

Why can't person on other side hear music playing in my phone during a call?

During a call, the other party listens to your voice through the microphone. When the music is played through the phone, due to Android limitations, the sound output cannot be recorded or shared directly. The music can be shared only through your microphone input.


2 Answers

I have found a workaround with this. I play an audio file on device's speakers with full sound when the phone state changes to TelephonyManager.CALL_STATE_OFFHOOK

This ensures that the user on the other side can hear the recording.

like image 136
Shafi Avatar answered Sep 22 '22 00:09

Shafi


In simple and clear words you cant stream any sound on an Incoming call

like image 43
ingsaurabh Avatar answered Sep 22 '22 00:09

ingsaurabh