How to start(play) video once buffer reaches 20% in android video view

十年热恋 提交于 2020-01-02 04:11:11

问题


I have a video view to play video by using url which comes from server. I want video to be played once buffering reaches 20% . So i have added listener for setOnBufferingUpdateListener to mediaplayer like below.

        Uri video = Uri.parse(videoUrl);
        videoView.setVideoURI(video);
        videoView.requestFocus();
        videoView.setOnPreparedListener(new OnPreparedListener() {
            public void onPrepared(MediaPlayer mp) {
                mp.setOnBufferingUpdateListener(Activity);
                progressVideoView.setVisibility(View.GONE);
                videoView.start();
            }
        });

        videoView.setOnErrorListener(new OnErrorListener() {

            @Override
            public boolean onError(MediaPlayer mp, int what, int extra) {
                Log.d("Error", "------>error"+what+"/"+extra);
                if (extra != 0) {
                    Utilities.showToast(ViewVlipActivity.this,
                            "Sorry, This video cannot be played.");
                }

                return false;
            }
        });
    videoView.setOnCompletionListener(new OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mp) {
            }

        });

My onbuffer listener as follows

@Override
public void onBufferingUpdate(MediaPlayer mp, int percent) {
    //seekbar.setSecondaryProgress(percent);
    Log.d("Buffer", "------>Buffer"+percent);
}

My problem is i could not get any log in buffer listener until the buffer ends. My video have duration of around 2 minute and it's MP4 video.

来源:https://stackoverflow.com/questions/29029597/how-to-startplay-video-once-buffer-reaches-20-in-android-video-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!