You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过InProgressListener自定义Mesibo通话背景与通话中音效

Mesibo通话背景与通话中音效自定义解决方案

一、通话背景自定义(InProgress阶段)

你已经通过IncomingListener实现来电背景修改,在通话进行中(InProgress阶段),可以通过InProgressListener的回调获取通话界面实例,直接设置背景,示例代码如下(以Android Java为例):

MesiboCall.InProgressListener inProgressListener = new MesiboCall.InProgressListener() {
    @Override
    public void onCallInProgress(MesiboCall.Call call, MesiboCall.CallProperties properties, boolean isIncoming) {
        // 获取通话界面根视图
        View callRootView = call.getView();
        if (callRootView != null) {
            // 方式1:设置自定义Drawable背景
            callRootView.setBackgroundResource(R.drawable.custom_call_background);
            
            // 方式2:设置纯色背景
            // callRootView.setBackgroundColor(Color.parseColor("#F5F5F5"));
            
            // 方式3:设置Bitmap背景
            // Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.custom_bg);
            // callRootView.setBackground(new BitmapDrawable(getResources(), bitmap));
        }
    }

    // 实现其他必填回调方法
    @Override
    public void onCallStatus(MesiboCall.Call call, int status, String message) {}

    @Override
    public void onCallStats(MesiboCall.Call call, MesiboCall.CallStats stats) {}
};

// 为通话注册InProgressListener
MesiboCall.addListener(inProgressListener);

二、通话中音效(PlayInCallSound)自定义问题解决

你通过InProgressListener修改音效未成功,大概率是调用时机或方式不对,推荐两种可行方案:

方案1:全局默认音效设置(初始化阶段)

在Mesibo初始化完成后,直接通过音频设置全局替换默认通话音效,这种方式覆盖所有通话场景:

// 初始化Mesibo后调用
MesiboAudioSettings audioSettings = new MesiboAudioSettings();
// 设置自定义通话中音效路径(支持本地资源或文件路径)
audioSettings.inCallSound = "android.resource://" + getPackageName() + "/" + R.raw.custom_in_call_sound;
// 可选:同时替换来电铃声、忙音等
audioSettings.ringtone = "android.resource://" + getPackageName() + "/" + R.raw.custom_ringtone;
// 应用设置
Mesibo.setAudioSettings(audioSettings);

方案2:InProgress阶段动态切换音效

如果需要在通话进行中动态修改音效,需确保在通话建立后调用音频管理器的方法:

@Override
public void onCallInProgress(MesiboCall.Call call, MesiboCall.CallProperties properties, boolean isIncoming) {
    MesiboAudioManager audioManager = Mesibo.getAudioManager();
    if (audioManager != null) {
        // 停止当前播放的默认音效
        audioManager.stopInCallSound();
        // 播放自定义音效(第二个参数true表示循环播放)
        audioManager.playInCallSound("android.resource://" + getPackageName() + "/" + R.raw.custom_in_call_sound, true);
    }
}

注意事项

  • 确保自定义音效文件格式为Mesibo支持的类型(如MP3、WAV);
  • 若使用本地文件路径,需申请READ_EXTERNAL_STORAGE权限(Android 10及以上可使用MediaStore或SAF);
  • 调用playInCallSound时,需确保通话处于活跃状态,避免时机过早导致无效。

内容的提问来源于stack exchange,提问作者Eko Yulianto

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.01 16:01:32