我正在做一个项目,我有许多产品类别,每个产品类别都包含一个视频。我通过从 Web 服务获取 url 来播放视频。当我第一次播放该视频时,它应该只从该 URL 下载该视频一次。并且当没有互联网连接时,它应该从下载位置(sdcard)播放。假设我已经为所有三种产品下载了 3 个视频,现在我必须在没有互联网的情况下播放这些视频,即来自 sdcard。这里出现了如何为各个产品获取特定视频路径的问题。我不必打开画廊。我必须直接播放该产品的视频。以及如何限制视频下载不止一次。我播放视频的代码是
private void playVideo(String path) {
dialog = new Dialog(this,android.R.style.Theme_Translucent_NoTitleBar);
dialog.setContentView(R.layout.layout_video_popup);
ImageView imgViewClose = (ImageView)dialog.findViewById(R.id.imgViewClose);
imgViewClose.setOnClickListener(this);
btnPlayPause = (Button) dialog.findViewById(R.id.button1);
btnPlayPause.setOnClickListener(this);
seekBar = (SeekBar) dialog.findViewById(R.id.seekBar1);
seekBar.setOnClickListener(this);
linearlayout = (LinearLayout) dialog.findViewById(R.id.linerlayout_bottom);
mVideoView = (VideoView)dialog.findViewById(R.id.videoView);
mVideoView.setOnTouchListener(this);
mVideoView.setOnPreparedListener(this);
mVideoView.setOnCompletionListener(this);
dialog.show();
playVideo(path, mVideoView);
AppLog.d("Video", "playVideo()", path);
}
private void playVideo(String path, VideoView mVideoView) {
if(path == null || path.isEmpty()) {
return;
}
try {
pDialpg = ProgressDialog.show(this, "Video", "Please wait..", false, true);
mVideoView.setVideoPath(path);
mVideoView.requestFocus();
RelativeLayout.LayoutParams relativeParams = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
relativeParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
relativeParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
mVideoView.setLayoutParams(relativeParams);
mVideoView.invalidate();
} catch (Exception e) {
// TODO: handle exception
}