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

.NET MAUI+Azure Communication Services移动端一对一通话单向音频问题

针对Azure Communication Services .NET MAUI移动端双向通话音频单向问题的排查方案
  • 强制激活移动端音频会话
    .NET MAUI在iOS/Android平台上,音频会话的主动激活是ACS音频流正常传输的前提,尤其是iOS系统对音频会话权限管控较严格。可在通话初始化前添加平台特定代码:

    // iOS平台代码
    var session = AVAudioSession.SharedInstance();
    NSError error;
    session.SetCategory(AVAudioSessionCategory.PlayAndRecord, out error);
    session.SetActive(true, out error);
    
    // Android平台代码
    var audioManager = (AudioManager)Platform.CurrentActivity.GetSystemService(Context.AudioService);
    audioManager.RequestAudioFocus(null, Stream.VoiceCall, AudioFocus.Gain);
    
  • 检查RemoteAudioStream绑定逻辑
    确保在通话建立前就注册参与者音频流监听事件,避免遗漏被叫方音频流的订阅与播放绑定:

    call.RemoteParticipantsUpdated += (s, e) =>
    {
        foreach (var participant in e.AddedParticipants)
        {
            participant.AudioStreamsUpdated += (ps, pe) =>
            {
                foreach (var stream in pe.AddedStreams)
                {
                    var audioPlayer = new AudioPlayer();
                    audioPlayer.SetSource(stream);
                    audioPlayer.Play();
                }
            };
        }
    };
    

    注意:若被叫方音频流延迟触发,需确保监听逻辑在通话初始化阶段就完成注册,而非通话过程中动态添加。

  • 强制指定音频输出设备
    移动端自动路由音频可能导致主叫方听不到声音,可强制切换到扬声器输出:

    var audioDevices = await CallClient.GetDeviceManager().GetAudioDevicesAsync();
    var speakerDevice = audioDevices.FirstOrDefault(d => d.Kind == AudioDeviceKind.Speaker);
    if (speakerDevice != null)
    {
        await CallClient.GetDeviceManager().SetActiveAudioDeviceAsync(speakerDevice);
    }
    
  • 采集ACS详细音频日志
    开启SDK verbose日志,重点追踪音频设备初始化、流订阅、会话状态变化:

    CallClient.SetLogLevel(LogLevel.Verbose);
    CallClient.LogMessage += (s, e) =>
    {
        Console.WriteLine($"ACS Audio Log: {e.Message}");
    };
    

    优先排查包含AudioStream、AudioDevice、Session关键词的日志,确认被叫方音频流是否被主叫方成功接收并初始化。

  • 升级ACS SDK版本
    部分旧版本Azure.Communication.Calling NuGet包存在移动端双向音频兼容性问题,建议升级至最新稳定版后重新测试。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.17 16:02:07