How to play wav file during voice call in Android 13 so that the receiver can listen the sound?

49 views Asked by At

I'm trying to build an application which can push an audio file inside the ongoing voice call so that receiver can listen the sound and we can record the audio through application

I found some codes which were working on the older versions. but in latest android versions like Android 12-13, they are not working. Even if i try to play an audio via speakers through MediaPlayer, the sounds gets too low that even microphone not able to fetch it.

1

There are 1 answers

1
Erkinjon On

Andoid studio kotlin code;

 var link ="http://...*.mp3";
        val mediaPlayer = MediaPlayer.create(this, Uri.parse(link))
        mediaPlayer.setAudioAttributes(
            AudioAttributes.Builder().setUsage((AudioAttributes.USAGE_MEDIA)).build()
        )
        mediaPlayer.setOnPreparedListener { it.start() }
        mediaPlayer.setOnCompletionListener {
            it.release()
        }
        mediaPlayer.setOnErrorListener { mp, what, extra ->
            false
        }