用xutils的Httputils 下载视频 其他安卓系统都可以实现。6.0的就是下载卡死。
HttpUtils http = new HttpUtils();
url = list.get(position).getFile_name();
resultPath = WinnerApplication.DEFAULT_VOICE_FOLDER + FileUtils.getFileName(url) + ".youzhi";//下载文件的跟路径
if ("缓存完成".equals(bufferVideo.getText()) == false) {
PRogDialog.showProgressDialog(context, "请稍后");
}
//下载视频文件
handler = http.download(url, resultPath, true, false, new RequestCallBack() {
@Override
public void onStart() {
super.onStart();
Log.e(TAG, "刚开始加载时的回调-----onStart");
bufferVideo.setText(context.getResources().getString(R.string.video_load));
}
@Override
public void onLoading(long total, long current, boolean isUploading) {
super.onLoading(total, current, isUploading);
Log.e(TAG, "正在加载中的回调----onLoading");
bufferVideo.setText(context.getResources().getString(R.string.video_download));
// bufferVideo.setText((int) (current * 100 / total) + "%");//显示下载的百分比
PRogDialog.showMessage("缓冲中 " + (int) (current * 100 / total) + "%");
}
@Override
public void onSuccess(ResponseInfo<File> arg0) {
// Intent it = new Intent(context,VideoInfoActivity.class);//下载成功跳转到观看视频界面
// it.putExtra("data", arg0.result.getAbsolutePath());
// startActivity(it);
// finish();item_video_button_shape
Log.e(TAG, "加载成功后的回调----onSuccess");
bufferVideo.setText("缓存完成");
bufferVideo.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.item_playvideo_button_shape));
retuteURL_string.set(position, arg0.result.getAbsolutePath());
//retuteURL = arg0.result.getAbsolutePath();
playTextView.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.item_video_button_shape));
deleteVideo.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.item_video_button_shape));
PRogDialog.ProgressDialogDismiss();
}
@Override
public void onFailure(HttpException arg0, String arg1) {
Log.e(TAG, "onFailure");
Log.i("fail-------------------", arg1);
if (FileUtils.isFileExist(resultPath)) {
//如果文件已存在,就直接观看
// Intent it = new Intent(context,VideoInfoActivity.class);
// it.putExtra("data", resultPath);
// startActivity(it);
// finish();
Log.e(TAG, "如果文件已经存在直接观看---FileUtils.isFileExist(resultPath)");
retuteURL_string.set(position, resultPath);
// retuteURL_string.get(position);
// retuteURL = resultPath;
bufferVideo.setText("缓存完成");
playTextView.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.item_video_button_shape));
} else {
Log.e(TAG, "else----下载失败...");
bufferVideo.setText("下载失败...");
//video_wait.setVisibility(View.GONE);
}
}
@Override
public void onCancelled() {
super.onCancelled();
}
});
代码如上
报错 直接onStart 然后等待1-2秒然后直接走的onFailure。
后来又单独写了个下载视频的小Demo 代码照这个扒的,居然可以下载。说明系统和代码都没有问题啊。 但是为什么6.0的 在项目那个就下载不来呢。。。。。。。大神恩帮帮忙