简体   繁体   中英

Webrtc Android DTMF Support

I am trying to implement DTMF for Android/iOS Application based out on WebRTC. Is there any API for DTMF for Android? 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. I havent tried it on iOS still, as I need to make it run on android first.

Please let me know if this is supported on Android/iOS or not? If yes, could any one please help me with the correct api's

libjingle version used : chrome 74.0.3729.169

I got it Working on both android and iOS . The Api createdtmfsender has been deprecated, details can be found here

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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