1

Whenever videoview is playing a video and there is a network connection drop and the video freezes, my code is not throwing an error even though I have set the videoview error listener.

public class MainActivity extends Activity {

static MediaController mc;
static VideoView vw;


/** Called when the activity is first created. */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_main);

    mc = new MediaController(this);

    vw = (VideoView) findViewById(R.id.videoView);

    vw.setVideoPath("http://173.45.164.105:1935/live/myStream/playlist.m3u8");

    vw.setOnErrorListener(new MediaPlayer.OnErrorListener() {
        @Override
        public boolean onError(MediaPlayer arg0, int arg1, int arg2) {
            vw.stopPlayback();
            vw.start();
            Log.i("VIDEO ERROR ", "FROZE");
            return true;
        }
    });
    vw.requestFocus();
    vw.start();
}

}

  • 1
    I am also facing the same problem. the screen just freezes with connection drop.. no errors.. have you resolved this issue?? – Fayyaz Ali Dec 07 '13 at 08:30

1 Answers1

0

To my understanding the native VideoView element only calls the onError() method when opening the video.

See: VideoView Source

In the openVideo() method -- called when setting the VideoView path/URI -- a couple of exceptions are handled by throwing a MediaPlayer.MEDIA_ERROR_UNKNOWN error.

I'm not positive what goes on in the background with the MediaPlayer whenever a connection is lost with the video source, but it seems that it simply waits indefinitely waiting to re-establish a connection. It will never throw an error via the onErrorListener.

However if you call the setVideoPath() or setVideoUri() method again it will call the onError() method b/c an Exception will be thrown in openVideo().

You'll have to either figure out some way to detect that the connection is lost or wait to see if the time on the video is getting updated and throw an error manually.

If anyone finds a better way to fix this let me know.