I have an Android project where I need to create a client application to receive one-time UDP or RTP video streams and play them. Unfortunately, I canβt get this work to work and to look a lot for a solution!
I am testing Xoom (Android 3.2) and Nexus S (Android 2.3.6) and I know that they can play content when using MX Player (a third-party media player application), but I canβt get my native media player to play the content. I tried using both simple VideoView and MediaPlayer, but both refused with the same error code, and I can not find any useful information.
H.264 video is encoded by aac audio.
In addition, the server is a third-party solution to which I do not have access (other than specifying udp or rtp), but, as I already said, streams can be played when using MX Player.
Here is a part of my media player:
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 am getting 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 also set permissions for the Internet.
Does anyone have any suggestions? I can not find any useful information anywhere.
Thanks.