title: Can't receive RTSP live stream from an IP cam
body: <p>I want to receive live streaming from an IP camera using RTSP, I'm getting <strong>'Can't play this video'</strong>, and the following Exception:</p>
  
  <pre><code>07-16 14:06:26.945: D/MediaPlayer(19411): setDataSource IOException happend : 
  07-16 14:06:26.945: D/MediaPlayer(19411): java.io.FileNotFoundException: No content provider: rtsp://192.168.30.108:554
  07-16 14:06:26.945: D/MediaPlayer(19411):   at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:1052)
  07-16 14:06:26.945: D/MediaPlayer(19411):   at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:907)
  07-16 14:06:26.945: D/MediaPlayer(19411):   at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:834)
  07-16 14:06:26.945: D/MediaPlayer(19411):   at android.media.MediaPlayer.setDataSource(MediaPlayer.java:973)
  07-16 14:06:26.945: D/MediaPlayer(19411):   at android.widget.VideoView.openVideo(VideoView.java:337)
  07-16 14:06:26.945: D/MediaPlayer(19411):   at android.widget.VideoView.setVideoURI(VideoView.java:247)
  07-16 14:06:26.945: D/MediaPlayer(19411):   at android.widget.VideoView.setVideoURI(VideoView.java:237)
  07-16 14:06:26.945: D/MediaPlayer(19411):   at com.example.video_rtsp.MainActivity$2.run(MainActivity.java:59)
  07-16 14:06:26.945: D/MediaPlayer(19411):   at android.os.Handler.handleCallback(Handler.java:733)
  07-16 14:06:26.945: D/MediaPlayer(19411):   at android.os.Handler.dispatchMessage(Handler.java:95)
  07-16 14:06:26.945: D/MediaPlayer(19411):   at android.os.Looper.loop(Looper.java:157)
  07-16 14:06:26.945: D/MediaPlayer(19411):   at android.app.ActivityThread.main(ActivityThread.java:5293)
  07-16 14:06:26.945: D/MediaPlayer(19411):   at java.lang.reflect.Method.invokeNative(Native Method)
  07-16 14:06:26.945: D/MediaPlayer(19411):   at java.lang.reflect.Method.invoke(Method.java:515)
  07-16 14:06:26.945: D/MediaPlayer(19411):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
  07-16 14:06:26.945: D/MediaPlayer(19411):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
  07-16 14:06:26.945: D/MediaPlayer(19411):   at dalvik.system.NativeStart.main(Native Method)
  07-16 14:06:26.945: D/MediaPlayer(19411): Couldn't open file on client side, trying server side
  07-16 14:06:26.955: V/MediaPlayer(19411): setVideoSurfaceTexture
  07-16 14:06:26.955: V/MediaPlayer-JNI(19411): setAudioStreamType: 3
  07-16 14:06:26.955: V/MediaPlayer(19411): MediaPlayer::setAudioStreamType
  07-16 14:06:26.955: V/MediaPlayer(19411): setVideoSurfaceTexture
  07-16 14:06:26.955: V/MediaPlayer(19411): prepareAsync
  07-16 14:06:26.965: D/ProgressBar(19411): setProgressDrawable drawableHeight = 48
  07-16 14:06:26.985: D/AbsSeekBar(19411): AbsSeekBar Constructor: misSeebarAnimationAvailable = true
  </code></pre>
  
  <p>I'm using the following way:</p>
  
  <pre><code>VideoView videoView = (VideoView) ((Activity) ctx).findViewById(R.id.videoView);
  
  //add controls to a MediaPlayer like play, pause.
  MediaController mc = new MediaController(ctx);
  videoView.setMediaController(mc);
  
  //Set the path of Video or URI
  videoView.setVideoURI(Uri.parse("rtsp://192.168.30.108:554"));
  
  //Set the focus
  videoView.requestFocus();
  </code></pre>
  
  <p><strong>can't say I'm sure this is the problem, but I think it's because this camera software needs authentication, but if so, I don't know how to provide the authentication to it.</strong></p>
  
  <hr>
  
  <p>After using MediaPlayer with setDataSource, I'm getting the following Exception:</p>
  
  <pre><code>07-21 12:04:11.677: W/System.err(17714): java.io.IOException: Prepare failed.: status=0x1
  07-21 12:04:11.677: W/System.err(17714):    at android.media.MediaPlayer.prepare(Native Method)
  </code></pre>
  
  <p>I'm not sure if that related to a wrong way in setting the headers or not :</p>
  
  <pre><code>Uri uri = Uri.parse("rtsp://192.168.30.108:554");
  Map&lt;String , String&gt; headres = new HashMap&lt;String, String&gt;();
  headres.put("Authorization", "Basic ce0ca0f0864513c28c7be98f0f929be7b1f5db79"); //Also tried it without "Basic"
  headres.put("encryption", "Default");
  headres.put("mac", "9002A9D89200");
  headres.put("random", "1715377261");
  headres.put("realm", "Login to 90:02:a9:d8:92:00");
  
  mediaPlayer.setDataSource(getApplicationContext(), uri, headres);
  </code></pre>
  
  <p>and this is a screenshots of login process headers and json data using firebug:</p>
  
  <p><img src="https://i.stack.imgur.com/prG1u.png" alt="enter image description here"></p>
  
  <p><img src="https://i.stack.imgur.com/TKQRr.png" alt="enter image description here"></p>