UDP Video Streaming on Android
Solution 1
I'm not sure Android natively supports UDP as it's not listed in the Network Protocols
http://developer.android.com/guide/appendix/media-formats.html
Many 3rd party mediaplayers are based upon the FFMPEG libraries. You may want to use FFMPEG in your project although that's a task in its own.
Solution 2
You can also stream via udp:// using the Vitamio library (it uses ffmpeg behind the scenes). http://www.vitamio.org/en/
theChumpus
Updated on September 06, 2020Comments
-
theChumpus over 3 years
I have an Android project where I need to build a client app to receive UDP or RTP unicast video streams and play them back. Unfortunately, I cannot seem to get this working and have searched extensively for a solution!
I have being testing on a Xoom (Android 3.2) and a Nexus S (Android 2.3.6) and know that they can play the content when using MX Player (a third-party media player app) as the client but I can't get the native media player to play back the content. I have tried using both a simple VideoView and a MediaPlayer but both fail with the same error code and I can't really find any helpful information on.
The video is H.264 encoded with aac audio.
Also, the server is a solution by a third-party which I have no access to (other than to specify udp or rtp) but as I said, when using MX Player, the streams can be played.
Here is the media player portion of my code:
public class Main extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); try { MediaPlayer player = new MediaPlayer(); SurfaceView surface = (SurfaceView) findViewById(R.id.video); player.setDisplay(surface.getHolder()); player.setDataSource(this, Uri.parse("udp://192.168.0.78:1234")); player.prepare(); player.setOnPreparedListener(new OnPreparedListener() { @Override public void onPrepared(MediaPlayer mp) { Log.d("SimpleVideoPlayer", "Starting player"); mp.start(); } }); player.setOnErrorListener(new OnErrorListener() { @Override public boolean onError(MediaPlayer mp, int what, int extra) { Log.d("SimpleVideoPlayer", "error with code: " + what); return false; } }); }catch(Exception e) { e.printStackTrace(); } }
The error I'm receiving is:
11-29 15:44:14.660: D/MediaPlayer(15451): Couldn't open file on client side, trying server side 11-29 15:44:14.670: E/MediaPlayer(15451): error (1, -2147483648) 11-29 15:44:14.670: W/System.err(15451): java.io.IOException: Prepare failed.: status=0x1 11-29 15:44:14.670: W/System.err(15451): at android.media.MediaPlayer.prepare(Native Method) 11-29 15:44:14.670: W/System.err(15451): at com.android.vidplayer.Main.onCreate(Main.java:26) 11-29 15:44:14.670: W/System.err(15451): at android.app.Activity.performCreate(Activity.java:4397) 11-29 15:44:14.670: W/System.err(15451): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048) 11-29 15:44:14.670: W/System.err(15451): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1804) 11-29 15:44:14.670: W/System.err(15451): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1856) 11-29 15:44:14.670: W/System.err(15451): at android.app.ActivityThread.access$500(ActivityThread.java:125) 11-29 15:44:14.670: W/System.err(15451): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1049) 11-29 15:44:14.670: W/System.err(15451): at android.os.Handler.dispatchMessage(Handler.java:99) 11-29 15:44:14.670: W/System.err(15451): at android.os.Looper.loop(Looper.java:132) 11-29 15:44:14.670: W/System.err(15451): at android.app.ActivityThread.main(ActivityThread.java:4157) 11-29 15:44:14.670: W/System.err(15451): at java.lang.reflect.Method.invokeNative(Native Method) 11-29 15:44:14.670: W/System.err(15451): at java.lang.reflect.Method.invoke(Method.java:491) 11-29 15:44:14.670: W/System.err(15451): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841) 11-29 15:44:14.670: W/System.err(15451): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599) 11-29 15:44:14.670: W/System.err(15451): at dalvik.system.NativeStart.main(Native Method)
I have set the Internet permissions also.
Does anybody have any suggestions please?? I can't find any helpful info anywhere.
Thanks.
-
theChumpus over 12 yearsYes it seems that's the case! I'd seen that page but was hoping someone had come up with their own solution!
-
Derzu about 11 years@theChumpus, Alex, Did you used witch ffmpeg lib? Did you used any one pre-compiled lib? Did you tried the stream h264 videos?
-
Alexander Kulyakhtin about 11 years@Derzu I've compiled ffmpeg under Unix as they do at code.google.com/p/dolphin-player. It plays h264 yes.
-
user1767754 over 9 yearsI've deleted my previous post, as i tested vitamio on my tablet (nexus-7) and it worked good.
-
Mithun Sarker Shuvro over 6 yearscould you kindly check stackoverflow.com/questions/45521175/… ?
-
Paul Gregoire over 6 yearsI'll have to look for my POC code for a particular project that I did 4 years ago; I don't have the actual work that was done for this of course, since I don't own it. Not making any promises, but I'll look.