title: Receive rtsp stream FROM DVR
body: <p>I have a DVR as a server which is connected to a camera.I'm trying to stream the camera's view into my android phone.I managed to do it through LAN,but failed through 3g/cellular</p>
  <p>I've done</p>
  <blockquote>
  <p>Port forwarding</p>
  <p>use DynDNS</p>
  <p>3rd party app called MEye(only app that works in my case)</p>
  </blockquote>
  <p>Here is the code</p>
  <pre><code>public class liveActivity extends Activity{
  
  final static String USERNAME = &quot;admin&quot;;
  final static String PASSWORD = &quot;&quot;;
  public static String domainName = &quot;xxx.dvrdns.org&quot;;
  public static int PORT = 2218;
  public static final String URL = &quot;rtsp://192.168.0.xxx:554/user=&quot; + USERNAME + &quot;&amp;password=&quot; + PASSWORD + &quot;&amp;channel=1&amp;stream=0.sdp?&quot;;
  public static final String URL2 = &quot;rtsp://&quot; + domainName + &quot;:&quot; + PORT + &quot;/user=&quot; + USERNAME + &quot;&amp;password=&quot; + PASSWORD + &quot;&amp;channel=1&amp;stream=1.sdp?real_stream--rtp-caching=100&quot;;
  
  private MediaPlayer mPlayer1;
  private MediaPlayer mPlayer2;
  SurfaceHolder.Callback mCallback1;
  SurfaceHolder.Callback mCallback2;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_live);
  
      mPlayer1 = new MediaPlayer();
  
      mCallback1 = new SurfaceHolder.Callback() {
          @Override
          public void surfaceCreated(SurfaceHolder surfaceHolder) {
  
              try {
  
                  mPlayer1.setDataSource(liveActivity.this, Uri.parse(URL2));
                  mPlayer1.setDisplay(surfaceHolder);
                  mPlayer1.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                      @Override
                      public void onPrepared(MediaPlayer mediaPlayer) {
                          mPlayer1.start();
                      }
                  });
                  mPlayer1.prepareAsync();
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
  
          @Override
          public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int i2, int i3) {
  
          }
  
          @Override
          public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
  
              mPlayer1.release();
          }
      };
  
      final SurfaceView surfaceView1 =
              (SurfaceView) findViewById(R.id.surfaceView1);
      // Configure the Surface View.
      surfaceView1.setKeepScreenOn(true);
      // Configure the Surface Holder and register the callback.
      SurfaceHolder holder1 = surfaceView1.getHolder();
      holder1.addCallback(mCallback1);
      holder1.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
  
  }
  </code></pre>
  <p>P.S I heard from a software engineer that RTSP is for local only.Is that why I can't stream via 3g?</p>