How to catch “Sorry, This video cannot be played” error on VideoView

后端 未结 4 2023
执念已碎
执念已碎 2021-01-01 08:49

I have a VideoView and I am streaming videos from a remote server. Most of the times It would play the videos very smoothly. But sometimes, it displays an error message \"So

4条回答
  •  囚心锁ツ
    2021-01-01 09:36

    The code I used for this:

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        setContentView(R.layout.main);
    
        vView = (VideoView) findViewById(R.id.videoView1);
    
        vSource = "android.resource://com.domain.android/"
                + R.raw.introductionportrait;
        vView.setVideoURI(Uri.parse(vSource));
    
        vView.setOnErrorListener(mOnErrorListener);
        vView.requestFocus();
        vView.start();
    }
    
    private OnErrorListener mOnErrorListener = new OnErrorListener() {
    
        @Override
        public boolean onError(MediaPlayer mp, int what, int extra) {
            // Your code goes here
            return true;
        }
    };
    

提交回复
热议问题