简体   繁体   English

Webrtc Android DTMF 支持

[英]Webrtc Android DTMF Support

I am trying to implement DTMF for Android/iOS Application based out on WebRTC.我正在尝试为基于 WebRTC 的 Android/iOS 应用程序实现 DTMF。 Is there any API for DTMF for Android?是否有适用于 Android 的 DTMF 的 API? I have tried calling the following:我试过调用以下方法:

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

I have tried using the above api's for javascript and it works well on browser, but could nt make it work on Android.我曾尝试将上述 api 用于 javascript,它在浏览器上运行良好,但无法在 Android 上运行。 I havent tried it on iOS still, as I need to make it run on android first.我还没有在 iOS 上尝试过,因为我需要先让它在 android 上运行。

Please let me know if this is supported on Android/iOS or not?请让我知道这是否在 Android/iOS 上受支持? If yes, could any one please help me with the correct api's如果是的话,任何人都可以帮助我使用正确的api

libjingle version used : chrome 74.0.3729.169使用的 libjingle 版本:chrome 74.0.3729.169

I got it Working on both android and iOS .我得到它在 android 和 iOS 上工作。 The Api createdtmfsender has been deprecated, details can be found here Api createdtmfsender已被弃用,可在此处找到详细信息

Android Code :安卓代码:

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 Code 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”);
     }];
     }
   }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM