Android VideoView OnErrorListener
<p>I'm currently working on a rtsp player in Android. I want to view the video stream from an IP camera from LAN.
I've implemented the rtsp into a VideoView class, but sometimes when I try to run it I get the error "Unable to play this video". So, I've inserted the OnErrorListener method hoping that when I get an error the rtsp would restart again, but without success.</p>

<p>How can I test the rtsp, to be sure that is ok and is running, before it shows up? And then if get an error how cand I restart the rtsp?</p>

<p>Here is my code:</p>

<pre><code>  public class videostream extends Activity {
    /** Called when the activity is first created. */


    private String videopath;
    private TextView textview;
    private DisplayMetrics dm;
    int percent, xvpx, yvpx;
    private FrameLayout videosurface;
    private mVideoView  videostream;

     @Override 
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    dm = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(dm);
    xvpx = dm.widthPixels;
    yvpx = dm.heightPixels;

    textview = (TextView) findViewById(R.id.textview);
    textview.setText(" asdf ");

    videosurface = (FrameLayout) findViewById(R.id.videosurface);


    videopath = "rtsp://192.168.1.19:554/0/1:1/main";

    Uri video = Uri.parse(videopath);
    videostream = new mVideoView(this);                 
    videostream.setVideoURI(video); 
    videostream.requestFocus();
    videostream.start();
    videosurface.addView(videostream);

    videostream.setOnCompletionListener(new OnCompletionListener() 
    {
        @Override
        public void onCompletion(MediaPlayer videostream) 
        {
            textview.setText( "onCompletion"); 
              videostream.start();
         }
    });

    videostream.setOnErrorListener(new OnErrorListener()
    {
       @Override
        public boolean onError(MediaPlayer videostream, int what, int extra)
        {

            textview.setText(String.valueOf(videostream) + "  "+ String.valueOf(what)+ "  " +String.valueOf(extra));
            videostream.start();
            return true;
        }           
    }) ;

}



    public class mVideoView extends VideoView {
            public mVideoView(Context context) {
                super(context);
            }

            @Override
            protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec)
            {
                 setMeasuredDimension(xvpx,yvpx);
            }                                           
        } 
</code></pre>

<p>}</p>
