问题
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