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.