title: Android IP Camera
body: <p>I'm looking for a good working solution to integrate an IP-Cameras video stream in my Android App. At the moment i am using the "Axis P1214-E" which has a good image quality, but i couldn't get a "LIVE" stream from it. Either the stream is very laggy or it's a few seconds delayed (sometimes even more) or the stream is shutting down after awhile. What i tried so far:</p>
  
  <ul>
  <li><p>Using a SurfaceView to get the MJPEG Stream as described in this post: <a href="https://stackoverflow.com/questions/3205191/android-and-mjpeg">Android and MJPEG</a>
  Problem: Lagging</p></li>
  <li><p>Using a WebView to get the RTSP stream:</p></li>
  </ul>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>public class MainActivity extends Activity {
  
   private static final String TAG = "VideoViewExample.MainActivity";
   private static final String RTSP_URL = "rtsp://ip/axis-media/media.amp"; 
   
   
   private VideoView videoView;
   private MediaController mediaController;
  
   private OnPreparedListener opl;
  
   private int position = 0;
  
   
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          
          if(savedInstanceState != null)
              position = savedInstanceState.getInt("POSITION");
          
          
          videoView = (VideoView) findViewById(R.id.videoView);        
        
          
          opl = new OnPreparedListener() {
     
     @Override
     public void onPrepared(MediaPlayer mp) {
          
      videoView.seekTo(position);
      
      if (position == 0) {
       videoView.start();
      }
      else {
       
       videoView.pause();
      }    
     }
    };
          
          if (mediaController == null){
           mediaController = new MediaController(this);
          }
          
          mediaController.setAnchorView(videoView);
          
          AsyncTask&lt;Void, Void, Void&gt; at = new AsyncTask&lt;Void, Void, Void&gt;() {
  
     @Override
     protected Void doInBackground(Void... params) {
      try{
             videoView.setMediaController(mediaController);              
                videoView.setVideoURI(Uri.parse(RTSP_URL));
            } catch (Exception e) {
             Log.d(TAG, e.getMessage());
            }
                    
            videoView.requestFocus();
            videoView.setOnPreparedListener(opl);          
            
      return null;
     }
           
    };
          at.execute();
           
      }
      
      @Override
      protected void onPause() {
          position = videoView.getCurrentPosition();
          super.onPause();
      }
      
      @Override
      public void onSaveInstanceState(Bundle outState) {
       
       super.onSaveInstanceState(outState);
       outState.putInt("POSITION", position);      
          
      }
  
  }</code></pre>
  </div>
  </div>
  
  Problem: Good video Quality, but delayed.</p>
  
  <ul>
  <li>Using external frameworks like FFMPEG and GSTREAMER (Only some examples so far)
  Problem: Also very laggy and/or delayed.</li>
  </ul>
  
  <p>Now i'm running out of ideas to get this working. It's very important for my Application that the stream is live and not lagging.
  I'm developing on a "Banana Pi" board with Android 4.2.2 (4.4 is possible as well).</p>
  
  <p>Does anybody know how to get this working? Or maybe should i use an other camera? Do you have any suggestions that would work well with android?</p>
  
  <p>Thanks in advance</p>
  
  <p>Christian</p>