RTP Sender : Android Application
RTP Receiver : VLC Player
Source :RtpSender (SVN)
Zipped Source : RTPSender.zip
Steps :
Create new android project with minimum sdk vesrion 12
Open the MainActivity.java and make below code changes
package com.javaorigin.rtpsender; import java.net.InetAddress; import java.net.NetworkInterface; import java.net.SocketException; import java.util.Enumeration; import android.app.Activity; import android.content.Context; import android.media.AudioManager; import android.net.rtp.AudioCodec; import android.net.rtp.AudioGroup; import android.net.rtp.AudioStream; import android.net.rtp.RtpStream; import android.os.Bundle; import android.os.StrictMode; import android.util.Log; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); try { AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE); audio.setMode(AudioManager.MODE_IN_COMMUNICATION); AudioGroup audioGroup = new AudioGroup(); audioGroup.setMode(AudioGroup.MODE_NORMAL); AudioStream audioStream = new AudioStream(InetAddress.getByAddress(getLocalIPAddress ())); audioStream.setCodec(AudioCodec.PCMU); audioStream.setMode(RtpStream.MODE_NORMAL); //set receiver(vlc player) machine ip address(please update with your machine ip) audioStream.associate(InetAddress.getByAddress(new byte[] {(byte)192, (byte)168, (byte)1, (byte)19 }), 22222); audioStream.join(audioGroup); } catch (Exception e) { Log.e("----------------------", e.toString()); e.printStackTrace(); } } public static byte[] getLocalIPAddress () { byte ip[]=null; try { for (Enumerationplease update the corresponding remote ip addressen = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) { NetworkInterface intf = en.nextElement(); for (Enumeration enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) { InetAddress inetAddress = enumIpAddr.nextElement(); if (!inetAddress.isLoopbackAddress()) { ip= inetAddress.getAddress(); } } } } catch (SocketException ex) { Log.i("SocketException ", ex.toString()); } return ip; } }
Add below permissions to AndroidManifest.xml
<uses-permission android:name="android.permission.INTERNET" > </uses-permission> <uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" > </uses-permission> <uses-permission android:name="android.permission.RECORD_AUDIO" > </uses-permission>Run the above rtp sender application
Now start the vlc player and click Media-->Open Network Stream menu
Enter the following url (please update with your machine ip) and click play button
rtp://192.168.1.19:22222
Now you can hear the voice and analysis the receiving data using following vlc options
Open Tools--->Codec Information
Thanks for the code.
ReplyDeleteI tried your RTPSender with only IP address change.
Codec info shows "Bits per sample: 16" and increases dropped count on and on.
I can't hear any sound on VLC.
Do you know why?
it might be codec issue on vlc , so please try some other codec like GSM,AMR,etc
DeleteI found the PCMA codec worked like a charm, however could not get the stream to work on Android Marshmallow (with permission checks).
DeleteHey, I have the same problem I was just wondering if you found any solution to that problem?
Deletethank you very muck , it help me a lot
ReplyDeleteThanks for the code.I'm trying to do voice over in internet.I want you to be between android devices.How can I do it in a simple way?
ReplyDeleteI have tried your sample but VLC fails to connect. I am 99% sure I have all IP's and ports set up correctly. There is just very little information given via logcat or vlc as to why the connection fails. Are there any suggestions to help debug the connection failure?
ReplyDeleteI get:
ReplyDeleteincompatible types
found : java.lang.Object
required: java.net.NetworkInterface
What could be the issue here?
You have to cast type
DeleteNetworkInterface to type (NetworkInterface)
and
InetAddress to type (InetAddress)
This comment has been removed by the author.
DeleteIn this line:
ReplyDeleteNetworkInterface intf = en.nextElement();
its the cast of the object
DeleteNetworkInterface intf = (NetworkInterface)en.nextElement();
Thanks for the code! I am creating a similar application but the android device is receiving an RTP packets. The codec is PCMU, and the audio is very crackly and it repeats itself for a second sometimes. Any ideas as to why this is?
ReplyDeleteThe above code seems to have errors. Could you post your working code?
Deletehi,
ReplyDeleteif i wont to live streaming video to VLC, how to do it.
thanks
nice
ReplyDeletevlc player download
really don't understand.
ReplyDeletecell phone ip 192.168.0.102
VLC(pc side) 192.168.0.101
rtp://192.168.0.102:22222 ==> VLC fail ??????
The IP you are worried about is the PC's IP. The Android device streams to the PC, the PC (VLC) tunes in to itself.
DeleteIs it possible to stream video in the same way?
ReplyDeleteI've been trying to figure this out myself. I need to send AND receive audio/video on Android.
DeleteThis comment has been removed by the author.
ReplyDeletepublic static byte[] getLocalIpAddress() {
ReplyDeletetry {
for (Enumeration en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
NetworkInterface intf = en.nextElement();
for (Enumeration enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
InetAddress inetAddress = enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress() && inetAddress instanceof Inet4Address) {
Log.e("ip",inetAddress.getHostAddress());
Log.e("ip2",""+inetAddress.getAddress());
return inetAddress.getAddress();
}
}
}
} catch (SocketException ex) {
ex.printStackTrace();
}
It worked, but I found the latency between my voice and the speaker in PC VLC, It is about 300ms, It is so bad. How can I decrease the latency?
ReplyDeletehow can we stream to multiple devices
ReplyDeletei have tried using thread to make it work for multiple devices but i am getting alot of jitter.
ReplyDeleteand how can we transfer the currently playing song. i mean i want the sound to be recieved by the mic.is there any possible solutions
i want to stream video on IP.
ReplyDeleteThanks for the sample code.
ReplyDeleteI managed to create an application on Android that receives and transmits stream rtp, but I have a problem. In reception I can not set the local port but is chosen randomly from "rtpstream" (chosen automatically according to rfc 3550). Any idea how to overcome the problem by forcing the local port to listen?
Thanks again for the help.
Can you share your sample code?
Deletewhy is this working on the same ip network group only?....i tried it by changing the ip network group or by changing the network carrier it does not works.
ReplyDeletesuppose my device ip address is '192.168.1.0'(my local wifi) and my receiver IP address is '192.168.3.1'(wifi at my friends house) then no voice can be heard !! is RTP streaming only for same network ip connected through a router ?? if not then please help me i am in serious trouble!! please do reply!!
Hello I tried to download the ZIP file but it seems to be broken... Where can I find it? thank you
ReplyDeleteIt's interesting that many of the bloggers your tips helped to clarify a few things for me as well as giving... very specific nice content.
ReplyDeleteBest Android Training in Velachery | android development course fees in chennai
thank you
ReplyDeleteI tried above code in Android Studio 2.3.3 , but I got following error:
ReplyDeleteThread[1,tid=18486,Native,Thread*=0x7f91e96a00,peer=0x7485af88,"main"] recursive
attempt to load library "/system/lib64/librtp_jni.so"
java.net.SocketException: Invalid argument
java.net.SocketException: Invalid argument
at android.net.rtp.RtpStream.create(Native Method)
at android.net.rtp.RtpStream.(RtpStream.java:71)
at android.net.rtp.AudioStream.(AudioStream.java:59)
at com.example.swanand.audiostreamdemo.MainActivity$1.onClick(MainActivity.java:91)
Any solution for this?
similar problem here. :(
Deleteappvn apk ios
ReplyDeletetutuapp apk ios
Dimana anda tidak hanya tertuju pada 1 permainan saja. Anda pun akan bisa bermain semua permainan sambil mempelajari cara cara permianan tersebut. Sehingga anda akan bisa mendapatkan strategi terbaik dalam menaklukan kemenangan pada meja permainan.
ReplyDeleteasikqq
http://dewaqqq.club/
http://sumoqq.today/
interqq
pionpoker
bandar ceme terpercaya
freebet tanpa deposit
paito warna
syair sgp
This comment has been removed by the author.
ReplyDeleteHi, I have tried the code but we I am getting the following error
ReplyDeleteE/AudioFlinger: Error when setting output stream volume: -38
Can you please post the complete code...
So another possible meaning for "play movies on Apple computer" would be a movie you've downloaded off the Internet. There's a lot of different types of video files (video just means moving pictures, just like a movie) that are sent by email, or that can be downloaded off a web site. howtodoninja
ReplyDeletepaito warna
ReplyDeletepaito
paito warna hongkong
paito warna hk
kingdomtoto
98toto
Togel
kinghorsetoto
Great to read article about berry update which i like reading about it.You have made an excellent effort in making this website which is appreciable. appvalley vip Sydney Brooke Simpson cotomovies streaming app
ReplyDeleteHey! Amazing work. With full of knowledge.Our Team resolve any glitches occurring while utilizing the software. Looking for QuickBooks Phone Number Contact us 1-855-756-1077. Our experts will assist you to fulfill your accounting needs. The solutions are accurate and time-saving.
ReplyDeleteThanks for sharing a useful knowledge-sharing blog.
ReplyDeleteIt helps in understanding and increase in knowledge.
Best Regards,
Prestashop addons
Prestashop modules
Prestashop addons
Magento extensions
PrestaShop Magento Opencart CRM Useful Blogs and How to do videos
very nice blog blog which provide great information Find best software service for
ReplyDeleteQuickBooks Customer Service
Firstgyan
ReplyDeleteWelcome to CapturedCurrentNews – Latest & Breaking India News 2021
ReplyDeleteHello Friends My Name Anthony Morris.latest and breaking news drupepower.com
Thank you so much for sharing this amazing information about. I really appreciate your hard work for writing this article thanks once again
ReplyDeletefor women skin tertinion cream
Thank you for sharing the information.
ReplyDeleteMPM Corner
Jumma Mubarak
tnmachiDa
teluguwap net
Coolmoviez
up Scholarship
Om Jai Jagdish
skymovies