在iOS物理设备上使用React Native WebRTC:接收到入站的RTP音频包,但没有声音输出(Android和 iOS模拟器可以正常工作)
我有一个React Native WebRTC的接收端流程,其中远端的音频/视频轨道是recvonly(仅接收)。
问题: 我最近把Expo SDK从 53升级到55,现在我的WebRTC音频只有在真实的iOS设备上听不到,安卓和模拟器正常。
- Android模拟器/设备:远端音频正常
- iOS模拟器:正常
- iOS真机:无声音
- 日志显示入站音频RTP字节数在增加,轨道处于活跃/未静音
版本: - React Native 0.83.6 - Expo 55.0.23 - react-native-webrtc 124.0.7
react-native-incall-manager 4.2.1
最小化流程
const pc = new RTCPeerConnection({ iceServers: [...] });
pc.addTransceiver("audio", { direction: "recvonly" });
pc.addTransceiver("video", { direction: "recvonly" });
pc.ontrack = (event) => {
console.log("ontrack", event.track.kind, event.track.enabled, event.track.muted, event.track.readyState);
};
await pc.setRemoteDescription(offer);
const answer = await pc.createAnswer();
await pc.setLocalDescription(answer);
统计显示进入的音频: inbound-rtp-audio bytes=1790 packets=5
inbound-rtp-audio bytes=27463 packets=79
inbound-rtp-audio bytes=61324 packets=179
另外已验证: - 音轨存在且处于活跃状态 - 信令和应答交换成功 - 远端语音的API触发返回200 - SDP包含音频和opus
我也在iOS上测试了RTCAudioSession的激活钩子:
RTCAudioSession.audioSessionDidActivate();
RTCAudioSession.audioSessionDidDeactivate();
我确定这是本地端的问题
问题: 在iOS原生端,什么条件会导致这种恰好出现的模式(RTP到达、轨道活跃,但在实体设备上没有声音输出),以及在react-native-webrtc中推荐的调试路径或修复方法?
为什么只在53->55之后并且仅在真实的iOS设备上发生
解决方案
你需要为iOS启动音频会话:
export default function useAudioRouting() {
useEffect(() => {
startAudioSession()
return () => {
AudioSession.stopAudioSession()
}
}, [])
}
async function startAudioSession() {
// Default config already correctly handles headset and bluetooth audio routing
await AudioSession.configureAudio({})
await AudioSession.setAppleAudioConfiguration({
audioCategory: "playAndRecord",
audioCategoryOptions: [
"mixWithOthers",
"allowAirPlay",
"allowBluetooth",
"allowBluetoothA2DP",
"defaultToSpeaker"
],
audioMode: "videoChat"
})
await AudioSession.startAudioSession()
}
更多细节 https://github.com/react-native-webrtc/react-native-incall-manager/issues/254
站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。