Play audio file during a call, however the person on the other end is not able to hear it

半腔热情 提交于 2019-12-09 07:57:06

问题


I want to play audio file during a call and i'm able to play it but when i make a call it play file only on that device on which i have installed the application. here is my sample code by which i have played the audio file.

 public void play() {

    bufferSize = AudioTrack.getMinBufferSize(16000,
            AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT);

    AudioTrack at = null;
    at = new AudioTrack(AudioManager.STREAM_VOICE_CALL,
            16000, AudioFormat.CHANNEL_CONFIGURATION_MONO,
            AudioFormat.ENCODING_PCM_16BIT, bufferSize, AudioTrack.MODE_STREAM);

    String filePath = Environment.getExternalStorageDirectory()
            .getAbsolutePath();
    String file = filePath + "/" + "myfile.wav";

            int i = 0;
    byte[] s = new byte[bufferSize];
    try {
        FileInputStream fin = new FileInputStream(file);
        BufferedInputStream bis = new BufferedInputStream(fin, 44000);
        DataInputStream dis = new DataInputStream(bis);

        at.play();

        while ((i = dis.read(s, 0, bufferSize)) > -1) {
            at.write(s, 0, i);

        }

        at.stop();
        at.release();
        dis.close();
        fin.close();

    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

This code works fine with me. But i want that this file would be able to hear by the other end person who make call. how could i do it??? Any idea?? i know android API doesn't allow to do it..but anyone who did it?? please give only genuine and accurate answer not assumptions.

来源:https://stackoverflow.com/questions/11823190/play-audio-file-during-a-call-however-the-person-on-the-other-end-is-not-able-t

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!