如何在某些Android设备(Twilio可编程视频)中修复远程音频偏低的问题?

时间:2019-10-24 04:10:34

标签: android audio twilio twilio-video

我已经集成了twilio可编程视频用于2个设备之间的视频通话,但是问题是,在某些android设备中,远程音频非常低。而且我已经测试了其他应用程序,例如whatsapp,在这些设备上whatsapp的声音很大。

我尝试过audioManager.setMode,但是它不起作用。

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video_call);

        audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
        audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);

        // Other functionalities
    }

请告知。

1 个答案:

答案 0 :(得分:2)

我按照建议的Twilio音频调试进行了操作,但是在听了他们的建议之后,却无所事事,我能够创建此函数,我可以使用Twilio在活动的onCreate中调用它

private fun requestAudioFocus() {
    val playbackAttributes = AudioAttributes.Builder()
        .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION)
        .setContentType(AudioAttributes.CONTENT_TYPE_SPEECH)
        .build()
    val focusRequest = AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN_TRANSIENT)
        .setAudioAttributes(playbackAttributes)
        .setAcceptsDelayedFocusGain(true)
        .setOnAudioFocusChangeListener { }
        .build()
    audioManager.requestAudioFocus(focusRequest)
    audioManager.isSpeakerphoneOn = !isHeadphonesPlugged(this)
}

检查耳机功能是

 fun isHeadphonesPlugged(context:Context): Boolean {
    val audioManager = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager?
    val audioDevices = audioManager!!.getDevices(AudioManager.GET_DEVICES_ALL)
    for (deviceInfo in audioDevices) {
        if (deviceInfo.type == AudioDeviceInfo.TYPE_WIRED_HEADPHONES
            || deviceInfo.type == AudioDeviceInfo.TYPE_WIRED_HEADSET) {
            return true
        }
    }
    return false
}

我在调用requestFocus()之前定义了音频管理器

audioManager = this.getSystemService(Context.AUDIO_SERVICE) as AudioManager

希望这对某人有帮助!