Commit 2aa99a57 authored by Hanruisong's avatar Hanruisong
Browse files

perf: 更新到v3.12.0

1.优化下载功能。
parent a80afec2
No preview for this file type
...@@ -33,7 +33,7 @@ dependencies { ...@@ -33,7 +33,7 @@ dependencies {
androidTestImplementation 'com.android.support.test:runner:1.0.2' androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
//获得场景视频SDK,必须引入 //获得场景视频SDK,必须引入
implementation 'com.bokecc:vod:3.11.0' implementation 'com.bokecc:vod:3.12.0'
//必须引用commonLib //必须引用commonLib
implementation 'com.bokecc:commonLib:0.1.12' implementation 'com.bokecc:commonLib:0.1.12'
//必须引用 //必须引用
......
...@@ -6,10 +6,13 @@ import android.content.SharedPreferences; ...@@ -6,10 +6,13 @@ import android.content.SharedPreferences;
import android.util.Log; import android.util.Log;
import android.widget.Toast; import android.widget.Toast;
import com.bokecc.sdk.mobile.download.VodDownloadManager;
import com.bokecc.sdk.mobile.drm.DRMServer; import com.bokecc.sdk.mobile.drm.DRMServer;
import com.bokecc.sdk.mobile.util.DWSdkStorage; import com.bokecc.sdk.mobile.util.DWSdkStorage;
import com.bokecc.sdk.mobile.util.DWStorageUtil; import com.bokecc.sdk.mobile.util.DWStorageUtil;
import com.bokecc.sdk.mobile.util.HttpUtil;
import com.bokecc.vod.data.ObjectBox; import com.bokecc.vod.data.ObjectBox;
import com.bokecc.vod.utils.MultiUtils;
public class HuodeApplication extends Application { public class HuodeApplication extends Application {
...@@ -27,6 +30,10 @@ public class HuodeApplication extends Application { ...@@ -27,6 +30,10 @@ public class HuodeApplication extends Application {
ObjectBox.init(this); ObjectBox.init(this);
initDWStorage(); initDWStorage();
startDRMServer(); startDRMServer();
//初始化VodDownloadManager
String downloadPath = MultiUtils.createDownloadPath();
//使用VodDownloadManager需要以单例VodDownloadManager.getInstance()的形式调用
VodDownloadManager.getInstance().init(context,ConfigUtil.USERID,ConfigUtil.API_KEY,downloadPath);
} }
public static Context getContext() { public static Context getContext() {
......
...@@ -16,16 +16,14 @@ import android.widget.Button; ...@@ -16,16 +16,14 @@ import android.widget.Button;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import com.bokecc.sdk.mobile.download.DownloadInfo; import com.bokecc.sdk.mobile.download.DownloadOperator;
import com.bokecc.sdk.mobile.download.DownloadModel; import com.bokecc.sdk.mobile.download.VodDownloadBean;
import com.bokecc.sdk.mobile.download.DownloaderHelper; import com.bokecc.sdk.mobile.download.VodDownloadManager;
import com.bokecc.sdk.mobile.download.OnDownloadInfoListener;
import com.bokecc.sdk.mobile.util.HttpUtil; import com.bokecc.sdk.mobile.util.HttpUtil;
import com.bokecc.vod.adapter.PlayVideoAdapter; import com.bokecc.vod.adapter.PlayVideoAdapter;
import com.bokecc.vod.data.DataSet; import com.bokecc.vod.data.DataSet;
import com.bokecc.vod.data.DataUtil; import com.bokecc.vod.data.DataUtil;
import com.bokecc.vod.data.HuodeVideoInfo; import com.bokecc.vod.data.HuodeVideoInfo;
import com.bokecc.vod.download.DownloadController;
import com.bokecc.vod.download.DownloadListActivity; import com.bokecc.vod.download.DownloadListActivity;
import com.bokecc.vod.download.DownloadService; import com.bokecc.vod.download.DownloadService;
import com.bokecc.vod.inter.SelectPlayer; import com.bokecc.vod.inter.SelectPlayer;
...@@ -49,7 +47,6 @@ import java.io.InputStreamReader; ...@@ -49,7 +47,6 @@ import java.io.InputStreamReader;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity { public class MainActivity extends AppCompatActivity {
private HeadGridView gv_video_list; private HeadGridView gv_video_list;
...@@ -64,6 +61,9 @@ public class MainActivity extends AppCompatActivity { ...@@ -64,6 +61,9 @@ public class MainActivity extends AppCompatActivity {
Manifest.permission.WRITE_EXTERNAL_STORAGE}; Manifest.permission.WRITE_EXTERNAL_STORAGE};
private ArrayList<HuodeVideoInfo> videoDatas; private ArrayList<HuodeVideoInfo> videoDatas;
/**
* @param savedInstanceState
*/
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
...@@ -73,7 +73,7 @@ public class MainActivity extends AppCompatActivity { ...@@ -73,7 +73,7 @@ public class MainActivity extends AppCompatActivity {
//初始化数据库和下载数据 没有开通授权播放和下载功能的账号 verificationCode可为空值 //初始化数据库和下载数据 没有开通授权播放和下载功能的账号 verificationCode可为空值
verificationCode = MultiUtils.getVerificationCode(); verificationCode = MultiUtils.getVerificationCode();
DownloadController.init(verificationCode); MultiUtils.showToast(MainActivity.this,"SDK版本:"+ HttpUtil.SDK_VERSION);
//初始化上传数据库 //初始化上传数据库
UploadController.init(); UploadController.init();
//申请存储权限 //申请存储权限
...@@ -287,7 +287,7 @@ public class MainActivity extends AppCompatActivity { ...@@ -287,7 +287,7 @@ public class MainActivity extends AppCompatActivity {
@Override @Override
protected void onDestroy() { protected void onDestroy() {
super.onDestroy(); super.onDestroy();
DataSet.saveDownloadData();
DataSet.saveUploadData(); DataSet.saveUploadData();
} }
......
...@@ -8,20 +8,20 @@ import android.widget.ImageView; ...@@ -8,20 +8,20 @@ import android.widget.ImageView;
import android.widget.ProgressBar; import android.widget.ProgressBar;
import android.widget.TextView; import android.widget.TextView;
import com.bokecc.sdk.mobile.download.DownloadOperator;
import com.bokecc.sdk.mobile.download.Downloader; import com.bokecc.sdk.mobile.download.Downloader;
import com.bokecc.vod.R; import com.bokecc.vod.R;
import com.bokecc.vod.download.DownloadWrapper;
import com.bokecc.vod.utils.MultiUtils; import com.bokecc.vod.utils.MultiUtils;
import java.util.List; import java.util.List;
public class DownloadViewAdapter extends BaseAdapter{ public class DownloadViewAdapter extends BaseAdapter{
private List<DownloadWrapper> downloadInfos; private List<DownloadOperator> downloadInfos;
private Context context; private Context context;
public DownloadViewAdapter(Context context, List<DownloadWrapper> downloadInfos){ public DownloadViewAdapter(Context context, List<DownloadOperator> downloadInfos){
this.context = context; this.context = context;
this.downloadInfos = downloadInfos; this.downloadInfos = downloadInfos;
} }
...@@ -43,7 +43,7 @@ public class DownloadViewAdapter extends BaseAdapter{ ...@@ -43,7 +43,7 @@ public class DownloadViewAdapter extends BaseAdapter{
@Override @Override
public View getView(int position, View convertView, ViewGroup parent) { public View getView(int position, View convertView, ViewGroup parent) {
DownloadWrapper wrapper = downloadInfos.get(position); DownloadOperator downloadOperator = downloadInfos.get(position);
ViewHolder holder = null; ViewHolder holder = null;
if (convertView == null) { if (convertView == null) {
...@@ -69,18 +69,18 @@ public class DownloadViewAdapter extends BaseAdapter{ ...@@ -69,18 +69,18 @@ public class DownloadViewAdapter extends BaseAdapter{
holder = (ViewHolder) convertView.getTag(); holder = (ViewHolder) convertView.getTag();
} }
holder.titleView.setText(wrapper.getDownloadInfo().getTitle()); holder.titleView.setText(downloadOperator.getVodDownloadBean().getFileName());
holder.statusView.setText(getStatusStr(wrapper.getStatus()) + ""); holder.statusView.setText(getStatusStr(downloadOperator.getStatus()) + "");
MultiUtils.showVideoCover(holder.iv_video_cover,wrapper.getDownloadInfo().getVideoCover()); MultiUtils.showVideoCover(holder.iv_video_cover,downloadOperator.getVodDownloadBean().getVideoCover());
if (wrapper.getStatus() == Downloader.DOWNLOAD) { if (downloadOperator.getStatus() == Downloader.DOWNLOAD) {
holder.speedView.setText(wrapper.getSpeed(context)); holder.speedView.setText(downloadOperator.getSpeed(context));
holder.progressView.setText(wrapper.getDownloadProgressText(context)); holder.progressView.setText(downloadOperator.getDownloadProgressText(context));
holder.downloadProgressBar.setProgress((int)wrapper.getDownloadProgressBarValue()); holder.downloadProgressBar.setProgress((int)downloadOperator.getDownloadProgressBarValue());
} else { } else {
holder.speedView.setText(""); holder.speedView.setText("");
holder.progressView.setText(wrapper.getDownloadProgressText(context)); holder.progressView.setText(downloadOperator.getDownloadProgressText(context));
holder.downloadProgressBar.setProgress((int)wrapper.getDownloadProgressBarValue()); holder.downloadProgressBar.setProgress((int)downloadOperator.getDownloadProgressBarValue());
} }
return convertView; return convertView;
......
...@@ -7,8 +7,9 @@ import android.view.ViewGroup; ...@@ -7,8 +7,9 @@ import android.view.ViewGroup;
import android.widget.BaseAdapter; import android.widget.BaseAdapter;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import com.bokecc.vod.R; import com.bokecc.vod.R;
import com.bokecc.vod.download.DownloadWrapper; import com.bokecc.vod.data.DownloadInfo;
import com.bokecc.vod.utils.MultiUtils; import com.bokecc.vod.utils.MultiUtils;
import java.util.List; import java.util.List;
...@@ -16,11 +17,11 @@ import java.util.List; ...@@ -16,11 +17,11 @@ import java.util.List;
public class DownloadedViewAdapter extends BaseAdapter{ public class DownloadedViewAdapter extends BaseAdapter{
private List<DownloadWrapper> downloadInfos; private List<DownloadInfo> downloadInfos;
private Context context; private Context context;
public DownloadedViewAdapter(Context context, List<DownloadWrapper> downloadInfos){ public DownloadedViewAdapter(Context context, List<DownloadInfo> downloadInfos){
this.context = context; this.context = context;
this.downloadInfos = downloadInfos; this.downloadInfos = downloadInfos;
} }
...@@ -42,7 +43,7 @@ public class DownloadedViewAdapter extends BaseAdapter{ ...@@ -42,7 +43,7 @@ public class DownloadedViewAdapter extends BaseAdapter{
@Override @Override
public View getView(int position, View convertView, ViewGroup parent) { public View getView(int position, View convertView, ViewGroup parent) {
DownloadWrapper wrapper = downloadInfos.get(position); DownloadInfo downloadInfo = downloadInfos.get(position);
ViewHolder holder = null; ViewHolder holder = null;
if (convertView == null) { if (convertView == null) {
...@@ -57,16 +58,16 @@ public class DownloadedViewAdapter extends BaseAdapter{ ...@@ -57,16 +58,16 @@ public class DownloadedViewAdapter extends BaseAdapter{
holder = (ViewHolder) convertView.getTag(); holder = (ViewHolder) convertView.getTag();
} }
holder.titleView.setText(wrapper.getDownloadInfo().getTitle()); holder.titleView.setText(downloadInfo.getTitle());
long end = wrapper.getDownloadInfo().getEnd(); long end = downloadInfo.getEnd();
if (end>0){ if (end>0){
holder.tv_filesize.setVisibility(View.VISIBLE); holder.tv_filesize.setVisibility(View.VISIBLE);
holder.tv_filesize.setText(Formatter.formatFileSize(context, wrapper.getDownloadInfo().getEnd())); holder.tv_filesize.setText(Formatter.formatFileSize(context, downloadInfo.getEnd()));
}else { }else {
holder.tv_filesize.setVisibility(View.INVISIBLE); holder.tv_filesize.setVisibility(View.INVISIBLE);
} }
MultiUtils.showVideoCover(holder.iv_video_cover,wrapper.getDownloadInfo().getVideoCover()); MultiUtils.showVideoCover(holder.iv_video_cover,downloadInfo.getVideoCover());
int firstSubtitleStatus = wrapper.getDownloadInfo().getFirstSubtitleStatus(); int firstSubtitleStatus = downloadInfo.getFirstSubtitleStatus();
if (firstSubtitleStatus==2){ if (firstSubtitleStatus==2){
holder.tv_subtitle_state.setVisibility(View.VISIBLE); holder.tv_subtitle_state.setVisibility(View.VISIBLE);
holder.tv_subtitle_state.setText("下载字幕失败"); holder.tv_subtitle_state.setText("下载字幕失败");
......
package com.bokecc.vod.adapter; package com.bokecc.vod.adapter;
import android.content.Context; import android.content.Context;
import android.graphics.Bitmap;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.format.Formatter; import android.text.format.Formatter;
import android.view.View; import android.view.View;
...@@ -11,11 +10,9 @@ import android.widget.ImageView; ...@@ -11,11 +10,9 @@ import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import com.bokecc.vod.R; import com.bokecc.vod.R;
import com.bokecc.vod.download.DownloadWrapper;
import com.bokecc.vod.upload.UploadWrapper; import com.bokecc.vod.upload.UploadWrapper;
import com.bokecc.vod.utils.MultiUtils; import com.bokecc.vod.utils.MultiUtils;
import java.io.File;
import java.util.List; import java.util.List;
......
...@@ -14,9 +14,6 @@ public class DataSet { ...@@ -14,9 +14,6 @@ public class DataSet {
uploadDBHelper = new UploadDBHelper(boxStore); uploadDBHelper = new UploadDBHelper(boxStore);
} }
public static void saveDownloadData(){
downloadDBHelper.saveDownloadData();
}
public static void saveUploadData(){ public static void saveUploadData(){
uploadDBHelper.saveUploadData(); uploadDBHelper.saveUploadData();
......
package com.bokecc.vod.data; package com.bokecc.vod.data;
import com.bokecc.vod.download.DownloadController;
import com.bokecc.vod.download.DownloadWrapper;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import io.objectbox.Box; import io.objectbox.Box;
...@@ -19,22 +15,6 @@ public class DownloadDBHelper { ...@@ -19,22 +15,6 @@ public class DownloadDBHelper {
box = boxStore.boxFor(DownloadInfo.class); box = boxStore.boxFor(DownloadInfo.class);
} }
public void saveDownloadData() {
ArrayList<DownloadInfo> downloadInfos = new ArrayList<>();
for (DownloadWrapper wrapper : DownloadController.downloadingList) {
DownloadInfo downloadInfo = wrapper.getDownloadInfo();
downloadInfos.add(downloadInfo);
}
for (DownloadWrapper wrapper : DownloadController.downloadedList) {
DownloadInfo downloadInfo = wrapper.getDownloadInfo();
downloadInfos.add(downloadInfo);
}
box.put(downloadInfos);
}
public List<DownloadInfo> getDownloadInfos() { public List<DownloadInfo> getDownloadInfos() {
List<DownloadInfo> lists = box.getAll(); List<DownloadInfo> lists = box.getAll();
return lists; return lists;
......
...@@ -39,6 +39,7 @@ public class DownloadInfo { ...@@ -39,6 +39,7 @@ public class DownloadInfo {
public DownloadInfo() { public DownloadInfo() {
} }
public DownloadInfo(String videoId, String title, int status, long start, long end, Date createTime) { public DownloadInfo(String videoId, String title, int status, long start, long end, Date createTime) {
......
package com.bokecc.vod.download;
import com.bokecc.sdk.mobile.download.Downloader;
import com.bokecc.vod.ConfigUtil;
import com.bokecc.vod.data.DataSet;
import com.bokecc.vod.data.DownloadInfo;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
/**
* 下载列表核心控制类
*/
public class DownloadController {
//下载中列表
public static ArrayList<DownloadWrapper> downloadingList = new ArrayList<>();
//下载完成列表
public static ArrayList<DownloadWrapper> downloadedList = new ArrayList<>();
//声明授权码
private static String verificationCode;
//初始化,需要在程序入口执行
public static void init(String veriCode) {
verificationCode = veriCode;
if (isBackDownload) {
return;
}
List<DownloadInfo> list = DataSet.getDownloadInfos();
// 清空数据
downloadingList.clear();
downloadedList.clear();
observers.clear();
for (DownloadInfo info : list) {
DownloadWrapper wrapper = new DownloadWrapper(info, verificationCode);
if (info.getStatus() == Downloader.FINISH) {
downloadedList.add(wrapper);
} else {
downloadingList.add(wrapper);
}
}
}
//新增下载信息
public static void insertDownloadInfo(String videoId, String veriCode, String title, int downloadMode, String videoCover) {
insertDownloadInfo(videoId, veriCode, title, downloadMode, videoCover, 0);
}
//新增下载信息
public static void insertDownloadInfo(String videoId, String veriCode, String title, int downloadMode, String videoCover, int definition) {
DownloadInfo info = new DownloadInfo(videoId, title, Downloader.WAIT, 0, 0, new Date());
info.setDefinition(definition);
info.setDownloadMode(downloadMode);
info.setVideoCover(videoCover);
DownloadWrapper wrapper = new DownloadWrapper(info, veriCode);
downloadingList.add(wrapper);
DataSet.addDownloadInfo(info);
}
//删除下载中信息
public static void deleteDownloadingInfo(int position) {
DownloadWrapper wrapper = downloadingList.remove(position);
wrapper.cancel();
DataSet.removeDownloadInfo(wrapper.getDownloadInfo());
}
//删除已下载的信息
public static void deleteDownloadedInfo(int position) {
DownloadWrapper wrapper = downloadedList.remove(position);
wrapper.cancel();
DataSet.removeDownloadInfo(wrapper.getDownloadInfo());
}
//更新下载状态信息
public static void update() {
synchronized (downloadingList) {
Iterator<DownloadWrapper> iterator = downloadingList.iterator();
int downloadCount = 0;
//列表里有下载完成的,则需要更新列表
while (iterator.hasNext()) {
DownloadWrapper wrapper = iterator.next();
if (wrapper.getStatus() == Downloader.FINISH) {
iterator.remove();
downloadedList.add(wrapper);
} else if (wrapper.getStatus() == Downloader.DOWNLOAD) {
downloadCount++;
}
}
//开启新的下载
if (downloadCount < ConfigUtil.DOWNLOADING_MAX) {
for (DownloadWrapper wrapper : downloadingList) {
if (wrapper.getStatus() == Downloader.WAIT) {
wrapper.start();
DataSet.updateDownloadInfo(wrapper.getDownloadInfo());
break;
}
}
}
notifyUpdate();
}
}
//连接网络后恢复下载
public static void resumeDownLoad() {
synchronized (downloadingList) {
Iterator<DownloadWrapper> iterator = downloadingList.iterator();
int downloadCount = 0;
int resumeCount = 0;
while (iterator.hasNext()) {
DownloadWrapper wrapper = iterator.next();
if (wrapper.getStatus() == Downloader.FINISH) {
iterator.remove();
downloadedList.add(wrapper);
} else if (wrapper.getStatus() == Downloader.DOWNLOAD) {
downloadCount++;
}
}
if (downloadCount < ConfigUtil.DOWNLOADING_MAX) {
for (DownloadWrapper wrapper : downloadingList) {
if (wrapper.getStatus() == Downloader.PAUSE) {
if (resumeCount < ConfigUtil.DOWNLOADING_MAX) {
wrapper.start();
DataSet.updateDownloadInfo(wrapper.getDownloadInfo());
resumeCount++;
} else {
wrapper.setToWait();
DataSet.updateDownloadInfo(wrapper.getDownloadInfo());
}
}
}
}
notifyUpdate();
}
}
//处理暂停和开始下载
public static void parseItemClick(int position) {
synchronized (downloadingList) {
DownloadWrapper wrapper = downloadingList.get(position);
if (wrapper.getStatus() == Downloader.DOWNLOAD) {
wrapper.pause();
} else if (wrapper.getStatus() == Downloader.PAUSE) {
int count = getDownloadingCount();
if (count < ConfigUtil.DOWNLOADING_MAX) {