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 {
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
//获得场景视频SDK,必须引入
implementation 'com.bokecc:vod:3.11.0'
implementation 'com.bokecc:vod:3.12.0'
//必须引用commonLib
implementation 'com.bokecc:commonLib:0.1.12'
//必须引用
......
......@@ -6,10 +6,13 @@ import android.content.SharedPreferences;
import android.util.Log;
import android.widget.Toast;
import com.bokecc.sdk.mobile.download.VodDownloadManager;
import com.bokecc.sdk.mobile.drm.DRMServer;
import com.bokecc.sdk.mobile.util.DWSdkStorage;
import com.bokecc.sdk.mobile.util.DWStorageUtil;
import com.bokecc.sdk.mobile.util.HttpUtil;
import com.bokecc.vod.data.ObjectBox;
import com.bokecc.vod.utils.MultiUtils;
public class HuodeApplication extends Application {
......@@ -27,6 +30,10 @@ public class HuodeApplication extends Application {
ObjectBox.init(this);
initDWStorage();
startDRMServer();
//初始化VodDownloadManager
String downloadPath = MultiUtils.createDownloadPath();
//使用VodDownloadManager需要以单例VodDownloadManager.getInstance()的形式调用
VodDownloadManager.getInstance().init(context,ConfigUtil.USERID,ConfigUtil.API_KEY,downloadPath);
}
public static Context getContext() {
......
......@@ -16,16 +16,14 @@ import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import com.bokecc.sdk.mobile.download.DownloadInfo;
import com.bokecc.sdk.mobile.download.DownloadModel;
import com.bokecc.sdk.mobile.download.DownloaderHelper;
import com.bokecc.sdk.mobile.download.OnDownloadInfoListener;
import com.bokecc.sdk.mobile.download.DownloadOperator;
import com.bokecc.sdk.mobile.download.VodDownloadBean;
import com.bokecc.sdk.mobile.download.VodDownloadManager;
import com.bokecc.sdk.mobile.util.HttpUtil;
import com.bokecc.vod.adapter.PlayVideoAdapter;
import com.bokecc.vod.data.DataSet;
import com.bokecc.vod.data.DataUtil;
import com.bokecc.vod.data.HuodeVideoInfo;
import com.bokecc.vod.download.DownloadController;
import com.bokecc.vod.download.DownloadListActivity;
import com.bokecc.vod.download.DownloadService;
import com.bokecc.vod.inter.SelectPlayer;
......@@ -49,7 +47,6 @@ import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
private HeadGridView gv_video_list;
......@@ -64,6 +61,9 @@ public class MainActivity extends AppCompatActivity {
Manifest.permission.WRITE_EXTERNAL_STORAGE};
private ArrayList<HuodeVideoInfo> videoDatas;
/**
* @param savedInstanceState
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -73,7 +73,7 @@ public class MainActivity extends AppCompatActivity {
//初始化数据库和下载数据 没有开通授权播放和下载功能的账号 verificationCode可为空值
verificationCode = MultiUtils.getVerificationCode();
DownloadController.init(verificationCode);
MultiUtils.showToast(MainActivity.this,"SDK版本:"+ HttpUtil.SDK_VERSION);
//初始化上传数据库
UploadController.init();
//申请存储权限
......@@ -287,7 +287,7 @@ public class MainActivity extends AppCompatActivity {
@Override
protected void onDestroy() {
super.onDestroy();
DataSet.saveDownloadData();
DataSet.saveUploadData();
}
......
......@@ -8,20 +8,20 @@ import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import com.bokecc.sdk.mobile.download.DownloadOperator;
import com.bokecc.sdk.mobile.download.Downloader;
import com.bokecc.vod.R;
import com.bokecc.vod.download.DownloadWrapper;
import com.bokecc.vod.utils.MultiUtils;
import java.util.List;
public class DownloadViewAdapter extends BaseAdapter{
private List<DownloadWrapper> downloadInfos;
private List<DownloadOperator> downloadInfos;
private Context context;
public DownloadViewAdapter(Context context, List<DownloadWrapper> downloadInfos){
public DownloadViewAdapter(Context context, List<DownloadOperator> downloadInfos){
this.context = context;
this.downloadInfos = downloadInfos;
}
......@@ -43,7 +43,7 @@ public class DownloadViewAdapter extends BaseAdapter{
@Override
public View getView(int position, View convertView, ViewGroup parent) {
DownloadWrapper wrapper = downloadInfos.get(position);
DownloadOperator downloadOperator = downloadInfos.get(position);
ViewHolder holder = null;
if (convertView == null) {
......@@ -69,18 +69,18 @@ public class DownloadViewAdapter extends BaseAdapter{
holder = (ViewHolder) convertView.getTag();
}
holder.titleView.setText(wrapper.getDownloadInfo().getTitle());
holder.statusView.setText(getStatusStr(wrapper.getStatus()) + "");
MultiUtils.showVideoCover(holder.iv_video_cover,wrapper.getDownloadInfo().getVideoCover());
holder.titleView.setText(downloadOperator.getVodDownloadBean().getFileName());
holder.statusView.setText(getStatusStr(downloadOperator.getStatus()) + "");
MultiUtils.showVideoCover(holder.iv_video_cover,downloadOperator.getVodDownloadBean().getVideoCover());
if (wrapper.getStatus() == Downloader.DOWNLOAD) {
holder.speedView.setText(wrapper.getSpeed(context));
holder.progressView.setText(wrapper.getDownloadProgressText(context));
holder.downloadProgressBar.setProgress((int)wrapper.getDownloadProgressBarValue());
if (downloadOperator.getStatus() == Downloader.DOWNLOAD) {
holder.speedView.setText(downloadOperator.getSpeed(context));
holder.progressView.setText(downloadOperator.getDownloadProgressText(context));
holder.downloadProgressBar.setProgress((int)downloadOperator.getDownloadProgressBarValue());
} else {
holder.speedView.setText("");
holder.progressView.setText(wrapper.getDownloadProgressText(context));
holder.downloadProgressBar.setProgress((int)wrapper.getDownloadProgressBarValue());
holder.progressView.setText(downloadOperator.getDownloadProgressText(context));
holder.downloadProgressBar.setProgress((int)downloadOperator.getDownloadProgressBarValue());
}
return convertView;
......
......@@ -7,8 +7,9 @@ import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.bokecc.vod.R;
import com.bokecc.vod.download.DownloadWrapper;
import com.bokecc.vod.data.DownloadInfo;
import com.bokecc.vod.utils.MultiUtils;
import java.util.List;
......@@ -16,11 +17,11 @@ import java.util.List;
public class DownloadedViewAdapter extends BaseAdapter{
private List<DownloadWrapper> downloadInfos;
private List<DownloadInfo> downloadInfos;
private Context context;
public DownloadedViewAdapter(Context context, List<DownloadWrapper> downloadInfos){
public DownloadedViewAdapter(Context context, List<DownloadInfo> downloadInfos){
this.context = context;
this.downloadInfos = downloadInfos;
}
......@@ -42,7 +43,7 @@ public class DownloadedViewAdapter extends BaseAdapter{
@Override
public View getView(int position, View convertView, ViewGroup parent) {
DownloadWrapper wrapper = downloadInfos.get(position);
DownloadInfo downloadInfo = downloadInfos.get(position);
ViewHolder holder = null;
if (convertView == null) {
......@@ -57,16 +58,16 @@ public class DownloadedViewAdapter extends BaseAdapter{
holder = (ViewHolder) convertView.getTag();
}
holder.titleView.setText(wrapper.getDownloadInfo().getTitle());
long end = wrapper.getDownloadInfo().getEnd();
holder.titleView.setText(downloadInfo.getTitle());
long end = downloadInfo.getEnd();
if (end>0){
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 {
holder.tv_filesize.setVisibility(View.INVISIBLE);
}
MultiUtils.showVideoCover(holder.iv_video_cover,wrapper.getDownloadInfo().getVideoCover());
int firstSubtitleStatus = wrapper.getDownloadInfo().getFirstSubtitleStatus();
MultiUtils.showVideoCover(holder.iv_video_cover,downloadInfo.getVideoCover());
int firstSubtitleStatus = downloadInfo.getFirstSubtitleStatus();
if (firstSubtitleStatus==2){
holder.tv_subtitle_state.setVisibility(View.VISIBLE);
holder.tv_subtitle_state.setText("下载字幕失败");
......
package com.bokecc.vod.adapter;
import android.content.Context;
import android.graphics.Bitmap;
import android.text.TextUtils;
import android.text.format.Formatter;
import android.view.View;
......@@ -11,11 +10,9 @@ import android.widget.ImageView;
import android.widget.TextView;
import com.bokecc.vod.R;
import com.bokecc.vod.download.DownloadWrapper;
import com.bokecc.vod.upload.UploadWrapper;
import com.bokecc.vod.utils.MultiUtils;
import java.io.File;
import java.util.List;
......
......@@ -14,9 +14,6 @@ public class DataSet {
uploadDBHelper = new UploadDBHelper(boxStore);
}
public static void saveDownloadData(){
downloadDBHelper.saveDownloadData();
}
public static void saveUploadData(){
uploadDBHelper.saveUploadData();
......
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 io.objectbox.Box;
......@@ -19,22 +15,6 @@ public class DownloadDBHelper {
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() {
List<DownloadInfo> lists = box.getAll();
return lists;
......
......@@ -39,6 +39,7 @@ public class DownloadInfo {
public DownloadInfo() {
}
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) {
wrapper.resume();
} else {
wrapper.setToWait();
}
}
DataSet.updateDownloadInfo(wrapper.getDownloadInfo());
}
}
//开启全部下载
public static void startAllDownload(int position) {
synchronized (downloadingList) {
DownloadWrapper wrapper = downloadingList.get(position);
if (wrapper.getStatus() == Downloader.PAUSE) {
int count = getDownloadingCount();
if (count < ConfigUtil.DOWNLOADING_MAX) {
wrapper.resume();
} else {
wrapper.setToWait();
}
}
DataSet.updateDownloadInfo(wrapper.getDownloadInfo());
}
}
//暂停全部下载
public static void pauseAllDownload(int position) {
synchronized (downloadingList) {
DownloadWrapper wrapper = downloadingList.get(position);
if (wrapper.getStatus() == Downloader.DOWNLOAD || wrapper.getStatus() == Downloader.WAIT) {
wrapper.pause();
}
DataSet.updateDownloadInfo(wrapper.getDownloadInfo());
}
}
//获取下载中的个数
public static int getDownloadingCount() {
int downloadCount = 0;
for (DownloadWrapper wrapper : downloadingList) {
if (wrapper.getStatus() == Downloader.DOWNLOAD) {
downloadCount++;
}
}
return downloadCount;
}
//获取已暂停或等待中的个数
public static int getPauseAndWaitCount() {
int downloadCount = 0;
for (DownloadWrapper wrapper : downloadingList) {
if (wrapper.getStatus() == Downloader.PAUSE || wrapper.getStatus() == Downloader.WAIT) {
downloadCount++;
}
}
return downloadCount;
}
private static boolean isBackDownload = false;
//如果设置为true,那么说明是后台下载中,list就不能被初始化,否则会导致出现野的downloader,无法控制
public static void setBackDownload(boolean isBack) {
isBackDownload = isBack;
}
public static List<Observer> observers = new ArrayList<>();
public static void attach(Observer o) {
observers.add(o);
}
public static void detach(Observer o) {
observers.remove(o);
}
public static void notifyUpdate() {
if (observers.size() > 0) {
for (Observer o : observers) {
o.update();
}
}
}
//观察者
public static interface Observer {
void update();
}
}
......@@ -13,6 +13,9 @@ import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import com.bokecc.sdk.mobile.download.DownloadConfig;
import com.bokecc.sdk.mobile.download.VodDownloadManager;
import com.bokecc.sdk.mobile.util.HttpUtil;
import com.bokecc.vod.R;
import com.bokecc.vod.ConfigUtil;
import com.bokecc.vod.utils.MultiUtils;
......
......@@ -11,6 +11,14 @@ import android.net.NetworkInfo;
import android.os.IBinder;
import android.support.annotation.Nullable;
import com.bokecc.sdk.mobile.download.VodDownloadBean;
import com.bokecc.sdk.mobile.download.VodDownloadManager;
import com.bokecc.sdk.mobile.util.HttpUtil;
import com.bokecc.vod.data.DataSet;
import com.bokecc.vod.data.DownloadInfo;
import com.bokecc.vod.utils.MultiUtils;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
......@@ -21,15 +29,11 @@ import java.util.TimerTask;
*/
public class DownloadService extends Service {
private NetChangedReceiver netReceiver;
//是否使用移动网络下载,可根据实际自行设置
private boolean isUseMobieNetwork = true;