android-How to enable cache or buffering when videoView have downloaded a video

僤鯓⒐⒋嵵緔 提交于 2019-12-24 05:24:48

问题


I'm showing video from internet by using videoView . it's ok and working fine . the only problem is , it plays the video every time I come to activity and it starts from 0 .

It's very bad , I want to cache videos or save them somehow to give users shows the videos without downloading them from scratch .

this is my code for playing videos :

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    Bundle bundle = getActivity().getIntent().getExtras();
    url=bundle.getString("url");
    onvan=bundle.getString("onvan");
    playvideo();
}

private void playvideo() {
    progressDialog = new ProgressDialog(getActivity());
    progressDialog.setMessage("Downloading");
    progressDialog.setCancelable(true);
    progressDialog.show();

    final VideoView videoView =(VideoView)view.findViewById(R.id.videoView);
    MediaController mediaController= new MediaController(getActivity());
    mediaController.setAnchorView(videoView);        
    Uri uri=Uri.parse("http://example.com/uploads/"+url); 
    videoView.setMediaController(mediaController);
    videoView.setVideoURI(uri);        
    videoView.requestFocus();

    videoView.start();

    videoView.setMediaController(mediaController);

    try{      
    videoView.setMediaController(mediaController);
    videoView.setVideoURI(uri);

    } catch (Exception e) {
      e.printStackTrace();
     }

    videoView.requestFocus();

    videoView.setOnPreparedListener(new OnPreparedListener() {

    public void onPrepared(MediaPlayer arg0) {
        progressDialog.dismiss();
        videoView.start();
    }
    });

}

The video sizes are between 10mb to 50mb .

How can I do so ?


回答1:


My suggestion is download video for first time like shown in here

Then start playing from external storage



来源:https://stackoverflow.com/questions/29184497/android-how-to-enable-cache-or-buffering-when-videoview-have-downloaded-a-video

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