我使用videoView显示来自互联网的视频。没关系,工作正常。唯一的问题是,它每次进入活动时播放视频,从0开始。
非常糟糕,我想缓存视频或以某种方式保存视频,以便用户无需从头开始下载即可显示视频。
这是我播放视频的代码:
@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();
}
});
}
视频大小介于10mb到50mb之间。
我该怎么办?