每当 videoview 正在播放视频并且网络连接断开并且视频冻结时,即使我设置了 videoview 错误侦听器,我的代码也不会引发错误。
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();
}
}