如何使用android.net.rtp包实现VoIP应用 [英] How implement the VOIP application using android.net.rtp package

查看:801
本文介绍了如何使用android.net.rtp包实现VoIP应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现使用AudioGroup和AudioStream类android.net.rtp包的VoIP应用。但是,我的应用程序无法正常工作。 加入的AudioGroup类对象的AudioStream对象后,它成功地发送UDP数据包。我检查,使用报文分析。但声音不从电话听到。我跑我的应用程序在2手机,并尝试他们之间交流的声音。

I am trying to implemented the VoIP application using the AudioGroup and AudioStream classes of the android.net.rtp package. But my application not function properly. After "Join" the "AudioGroup" class object with the "AudioStream" object, its send udp packets successfully. I checked that using the packet analyzer. But voice is not hear from the phone. I run my application in 2 phones and try communicate voice between them.

在下面我提到我的源$ C ​​$ C。

In below I mention my source code.

public class MainActivity extends Activity {
private AudioStream audioStream;
private AudioGroup audioGroup;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

try {
   audioGroup = new AudioGroup();
   audioGroup.setMode(AudioGroup.MODE_NORMAL);        
   audioStream = new AudioStream(InetAddress.getByAddress(new byte[] {(byte)192, (byte)168, (byte)1, (byte)4 }));
   audioStream.setCodec(AudioCodec.PCMU);
   audioStream.setMode(RtpStream.MODE_NORMAL);
   audioStream.associate(InetAddress.getByAddress(new byte[] {(byte)192, (byte)168, (byte)1, (byte)2 }), 5004);
   audioStream.join(audioGroup);
   AudioManager Audio =  (AudioManager) getSystemService(Context.AUDIO_SERVICE); 
   Audio.setMode(AudioManager.MODE_IN_COMMUNICATION);
} 
catch (SocketException e) { e.printStackTrace();} 
catch (UnknownHostException e) { e.printStackTrace();} 
catch (Exception ex) { ex.printStackTrace();}
}

我在Manifestfile设置此权限。

I set this permissions in the Manifestfile.

<uses-permission android:name="android.permission.USE_SIP" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-feature android:name="android.hardware.sip.voip" android:required="true" />
<uses-feature android:name="android.hardware.wifi" android:required="true" />
<uses-feature android:name="android.hardware.microphone" android:required="true" />


我使用的是三星GALAXY S3手机采用Android 4.0操作系统


I am using the Samsung GALAXY S3 phone with Android 4.0 OS

推荐答案

关键是要获得端口映射正确。您需要使用从audioStream.getLocalPort(端口号),并将其发送端口号对端的SDP包作为SIP信令研究。

The trick is to get the port mapping correct. You need to use the port number from audioStream.getLocalPort() and send this port number to the peer in the SDP packet as SIP signalling.

看看它实现SIP功能本示例应用程序 <一href="https://github.com/Mobicents/restcomm-android-sdk/tree/master/Examples/JAIN%20SIP">https://github.com/Mobicents/restcomm-android-sdk/tree/master/Examples/JAIN%20SIP

Check out this example application which implements sip functionality https://github.com/Mobicents/restcomm-android-sdk/tree/master/Examples/JAIN%20SIP

这篇关于如何使用android.net.rtp包实现VoIP应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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