use of com.zhy.http.okhttp.callback.FileCallBack in project Mvp-Rxjava-Retrofit-dagger2 by pengMaster.
the class MediaRecordPresenter method downLoadVideo.
/**
* 1.视频已存在 加载本地视频
* 2.视频不存在 下载
*
* @param fileUrl 下载地址
* @param name 视频名字
* @param progressBar 进度条
*/
public void downLoadVideo(String fileUrl, String name, final ProgressBar progressBar) {
String packagePath = FileUtils.getPackagePath(mApplication) + "/video/";
boolean dirs = FileUtils.createDirs(packagePath);
if (!dirs) {
mRootView.showMessage("文件夹创建失败");
}
String videoPath = packagePath + name;
File videoFile = new File(videoPath);
if (videoFile.exists()) {
mRootView.startVideo(videoFile);
return;
} else {
progressBar.setVisibility(View.VISIBLE);
progressBar.setMax(100);
}
OkHttpUtils.get().url(fileUrl).addParams("", "").build().execute(new FileCallBack(packagePath, name) {
@Override
public void inProgress(float progress) {
int i = (int) (progress * 100);
progressBar.setProgress(i);
}
@Override
public void onError(Request request, Exception e) {
progressBar.setVisibility(View.GONE);
e.printStackTrace();
}
@Override
public void onResponse(File response) {
progressBar.setVisibility(View.GONE);
mRootView.startVideo(response);
}
});
}
Aggregations