Webrtc Android DTMF 支持 [英] Webrtc Android DTMF Support

查看:43
本文介绍了Webrtc Android DTMF 支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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);

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

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.

请告诉我这是否在 Android/iOS 上受支持?如果是的话,任何人都可以帮我提供正确的 api

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 版本:chrome 74.0.3729.169

libjingle version used : chrome 74.0.3729.169

推荐答案

I got it 可在 android 和 iOS 上运行.Api createdtmfsender 已被弃用,详情请见 这里

I got it Working on both android and iOS . The Api createdtmfsender has been deprecated, details can be found 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 支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆