Webrtc Android DTMF 支持

标签 webrtc rtcpeerconnection peer-connection webrtc-android webrtc-ios

我正在尝试为基于 WebRTC 的 Android/iOS 应用程序实现 DTMF。 是否有适用于 Android 的 DTMF API?我试过调用以下内容:

m_peerConnectionFactory.createdtmfsender(localAudioTrack);
m_peerConnectionFactory.insertDtmf(tone, duration,gap);

我尝试过将上述 api 用于 javascript,它在浏览器上运行良好,但无法在 Android 上运行。 我还没有在 iOS 上尝试过,因为我需要先让它在 Android 上运行。

请告诉我Android/iOS 是否支持此功能?如果是的话,有人可以帮我找到正确的 api 吗

使用的 libjingle 版本:chrome 74.0.3729.169

最佳答案

我得到它在 android 和 iOS 上工作。 Api createdtmfsender 已被弃用,详情请见here

安卓代码:

RtpSender m_audioSender = null;
for (RtpSender sender : m_peerConnection.getSenders()) {
//m_peerConnection is object of webRTC peerconnection
  if (sender.track().kind().equals("audio")) {
   m_audioSender = sender;
  } 
}
if (m_audioSender != null) {
  DtmfSender dtmfSender = m_audioSender.dtmf();
  dtmfSender.insertDtmf(m_tone, 1000, 500);//Here the timers are in ms

iOS 代码

-(void)dtmfTonePlayer: (NSString *)dtmfTone {
    RTCRtpSender* m_audioSender = nil ;
    for( RTCRtpSender *rtpSender in m_peerConnection.senders){
     if([[[rtpSender track] kind] isEqualToString:@“audio”]) {
       DLog(@“Assigning audio to rtp sender”);
       m_audioSender = rtpSender;
     }  
    }
     if(m_audioSender){
     NSOperationQueue *queue = [[NSOperationQueue alloc] init];
     [queue addOperationWithBlock:^{
        BOOL istoneplayed = [m_audioSender.dtmfSender insertDtmf :(NSString *)dtmfTone 
        duration:(NSTimeInterval)2 interToneGap:(NSTimeInterval)0.5];
        NSLog(@“DTMF Tone played :: [%s]“, istoneplayed ? “true” : “false”);
     }];
     }
   }

关于Webrtc Android DTMF 支持,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59954104/

相关文章:

swift - iOS Swift WebRTC - 无法设置远程优惠 sdp : Failed to set remote video description send parameters

android - 用于移动(Android/IOS)和 Web 应用程序的 VOIP 库

ios - 从锁定屏幕接听电话时 Callkit 和 Webrtc 无音频

javascript - 多个 webRTC 连接

javascript - 如何在 Chrome 中为 WebRTC 调用者设置远程描述而不会出错?

javascript - 从 WebRTC 访问 RTP 时间戳

ios - 如何在 webrtc ios 应用程序中实现 "Who is talking?"功能?

webrtc - 为什么我的回合服务器不工作?

javascript - 创建PeerConnection失败,异常: Failed to construct 'RTCSessionDescription' : parameter 1 ('descriptionInitDict' ) is not an object