Commit 63ea7af0 authored by zhangww's avatar zhangww
Browse files

3.16.6

1.添加自定义跑马灯数据源
2.添加视频播放状态
3.bug fix
parent 73940fe1
......@@ -61,7 +61,7 @@ dependencies {
implementation 'com.github.bumptech.glide:glide:4.9.0'
implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.bokecc:CCVOD:3.16.5'
implementation 'com.bokecc:CCVOD:3.16.6'
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'com.umeng.umsdk:common:9.4.0'
......
package com.bokecc.vod;
import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import androidx.test.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;
import org.junit.Test;
import org.junit.runner.RunWith;
......
{
"loop": -1,
"type": "image",
"text": {
"content": "跑马灯",
"font_size": 50,
"color": "#e8cea0"
},
"image": {
"image_url": "https://console.bokecc.com/img/logo.9ba43539.png",
"width": 228,
"height": 60
},
"action": [
{
"index": 0,
"duration": 3000,
"start": {
"xpos": 0.012,
"ypos": 0,
"alpha": 0.8
},
"end": {
"xpos": 0.912,
"ypos": 0.823,
"alpha": 0.8
}
},
{
"index": 1,
"duration": 5000,
"start": {
"xpos": 0.312,
"ypos": 0.823,
"alpha": 0.8
},
"end": {
"xpos": 0.912,
"ypos": 0.123,
"alpha": 0.2
}
}
]
}
\ No newline at end of file
......@@ -11,6 +11,7 @@ public class ConfigUtil {
* 391E6E3340A00767
*/
public static final String USER_ID = "391E6E3340A00767";
/**
* 可以替换为自己的API_KEY
* T8WdOUuvFEiOsou1xjDr4U73v12M7iNa
......
......@@ -8,6 +8,7 @@ import android.widget.Toast;
import androidx.multidex.MultiDexApplication;
import com.bokecc.common.application.ApplicationData;
import com.bokecc.sdk.mobile.download.VodDownloadManager;
import com.bokecc.sdk.mobile.drm.DRMServer;
import com.bokecc.sdk.mobile.play.InitializeManager;
......@@ -20,6 +21,7 @@ import com.umeng.commonsdk.UMConfigure;
/**
* HuodeApplication
*
* @author Zhang
*/
@SuppressLint("StaticFieldLeak")
......
......@@ -18,6 +18,7 @@ import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import com.bokecc.sdk.mobile.core.Core;
import com.bokecc.vod.adapter.PlayVideoAdapter;
import com.bokecc.vod.data.DataSet;
import com.bokecc.vod.data.DataUtil;
......@@ -45,15 +46,17 @@ import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.concurrent.ExecutionException;
/**
* MainActivity
*
* @author CC
*/
public class MainActivity extends AppCompatActivity {
private HeadGridView gv_video_list;
private PlayVideoAdapter playVideoAdapter;
private ImageView iv_account_info, iv_upload, iv_download, iv_main_img;
private View headView;
private LinearLayout ll_retry;
private String verificationCode;
private Button btn_retry;
private ImageView ivMainImg;
private LinearLayout llRetry;
private static final String[] PERMISSIONS_STORAGE = {
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE};
......@@ -66,10 +69,8 @@ public class MainActivity extends AppCompatActivity {
setContentView(R.layout.activity_main);
MultiUtils.setStatusBarColor(this, R.color.transparent, true);
initView();
//初始化数据库和下载数据 没有开通授权播放和下载功能的账号 verificationCode可为空值
verificationCode = MultiUtils.getVerificationCode();
String verificationCode = MultiUtils.getVerificationCode();
//初始化上传数据库
UploadController.init();
//申请存储权限
......@@ -78,15 +79,12 @@ public class MainActivity extends AppCompatActivity {
} else {
MultiUtils.createDownloadPath();
}
//启动下载service
Intent intent = new Intent(this, DownloadService.class);
startService(intent);
//启动上传service
Intent uploadIntent = new Intent(this, UploadService.class);
startService(uploadIntent);
//请求数据
initData();
}
......@@ -101,25 +99,22 @@ public class MainActivity extends AppCompatActivity {
private void initView() {
gv_video_list = findViewById(R.id.gv_video_list);
iv_account_info = findViewById(R.id.iv_account_info);
iv_upload = findViewById(R.id.iv_upload);
iv_download = findViewById(R.id.iv_download);
ll_retry = findViewById(R.id.ll_retry);
btn_retry = findViewById(R.id.btn_retry);
headView = LayoutInflater.from(MainActivity.this).inflate(R.layout.headview_main, null);
iv_main_img = headView.findViewById(R.id.iv_main_img);
gv_video_list.addHeaderView(headView);
HeadGridView gvVideoList = findViewById(R.id.gv_video_list);
ImageView ivAccountInfo = findViewById(R.id.iv_account_info);
ImageView ivUpload = findViewById(R.id.iv_upload);
ImageView ivDownload = findViewById(R.id.iv_download);
llRetry = findViewById(R.id.ll_retry);
Button btnRetry = findViewById(R.id.btn_retry);
View headView = LayoutInflater.from(MainActivity.this).inflate(R.layout.headview_main, null);
ivMainImg = headView.findViewById(R.id.iv_main_img);
gvVideoList.addHeaderView(headView);
videoDatas = new ArrayList<>();
//配置自己的视频时取消这行注释
//TODO 配置自己的视频时取消这行注释
// videoDatas = DataUtil.getVideoList();
playVideoAdapter = new PlayVideoAdapter(MainActivity.this, videoDatas);
gv_video_list.setAdapter(playVideoAdapter);
iv_main_img.setImageResource(R.mipmap.iv_default_img);
gv_video_list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
gvVideoList.setAdapter(playVideoAdapter);
ivMainImg.setImageResource(R.mipmap.iv_default_img);
gvVideoList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
showKnowledge = position == 0;
......@@ -127,8 +122,7 @@ public class MainActivity extends AppCompatActivity {
selectPlayer(item);
}
});
iv_main_img.setOnClickListener(new View.OnClickListener() {
ivMainImg.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (videoDatas != null && videoDatas.size() > 0) {
......@@ -138,36 +132,31 @@ public class MainActivity extends AppCompatActivity {
}
}
});
iv_account_info.setOnClickListener(new View.OnClickListener() {
ivAccountInfo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, AccountInfoActivity.class));
}
});
iv_download.setOnClickListener(new View.OnClickListener() {
ivDownload.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, DownloadListActivity.class));
}
});
iv_upload.setOnClickListener(new View.OnClickListener() {
ivUpload.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, UploadManageActivity.class));
}
});
btn_retry.setOnClickListener(new View.OnClickListener() {
btnRetry.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ll_retry.setVisibility(View.GONE);
llRetry.setVisibility(View.GONE);
initData();
}
});
}
......@@ -216,13 +205,16 @@ public class MainActivity extends AppCompatActivity {
private void initData() {
//TODO 配置自己的视频时取消这行注释
// videoDatas = DataUtil.getVideoList();
new Thread(new Runnable() {
@Override
public void run() {
request();
}
}).start();
Core.getInstance().getExecutorSupplier()
.forBackgroundTasks()
.execute(new Runnable() {
@Override
public void run() {
request();
}
});
}
private void request() {
......@@ -268,7 +260,7 @@ public class MainActivity extends AppCompatActivity {
playVideoAdapter.notifyDataSetChanged();
HuodeVideoInfo huodeVideoInfo = videoDatas.get(0);
if (huodeVideoInfo != null) {
MultiUtils.showCornerVideoCover(iv_main_img, huodeVideoInfo.getVideoCover());
MultiUtils.showCornerVideoCover(ivMainImg, huodeVideoInfo.getVideoCover());
}
}
});
......@@ -276,7 +268,7 @@ public class MainActivity extends AppCompatActivity {
runOnUiThread(new Runnable() {
@Override
public void run() {
ll_retry.setVisibility(View.VISIBLE);
llRetry.setVisibility(View.VISIBLE);
}
});
e.printStackTrace();
......@@ -288,7 +280,7 @@ public class MainActivity extends AppCompatActivity {
e.printStackTrace();
}
}
if (connection != null) {//关闭连接
if (connection != null) {
connection.disconnect();
}
}
......
......@@ -15,72 +15,75 @@ import com.bokecc.vod.utils.MultiUtils;
import java.util.List;
public class DownloadedViewAdapter extends BaseAdapter{
/**
* DownloadedViewAdapter
*
* @author CC
*/
public class DownloadedViewAdapter extends BaseAdapter {
private List<DownloadInfo> downloadInfos;
private final List<DownloadInfo> downloadInfoArray;
private Context context;
private final Context context;
public DownloadedViewAdapter(Context context, List<DownloadInfo> downloadInfos){
this.context = context;
this.downloadInfos = downloadInfos;
}
public DownloadedViewAdapter(Context context, List<DownloadInfo> downloadInfoArray) {
this.context = context;
this.downloadInfoArray = downloadInfoArray;
}
@Override
public int getCount() {
return downloadInfos.size();
}
@Override
public int getCount() {
return downloadInfoArray.size();
}
@Override
public Object getItem(int position) {
return downloadInfos.get(position);
}
@Override
public Object getItem(int position) {
return downloadInfoArray.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
DownloadInfo downloadInfo = downloadInfos.get(position);
ViewHolder holder = null;
@Override
public View getView(int position, View convertView, ViewGroup parent) {
DownloadInfo downloadInfo = downloadInfoArray.get(position);
ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
convertView = View.inflate(context, R.layout.item_downloaded_video, null);
holder.tvFileSize = convertView.findViewById(R.id.tv_filesize);
holder.titleView = convertView.findViewById(R.id.downloaded_title);
holder.ivVideoCover = convertView.findViewById(R.id.iv_video_cover);
holder.tvSubtitleState = convertView.findViewById(R.id.tv_subtitle_state);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.titleView.setText(downloadInfo.getTitle());
long end = downloadInfo.getEnd();
if (end > 0) {
holder.tvFileSize.setVisibility(View.VISIBLE);
holder.tvFileSize.setText(Formatter.formatFileSize(context, downloadInfo.getEnd()));
} else {
holder.tvFileSize.setVisibility(View.INVISIBLE);
}
MultiUtils.showVideoCover(holder.ivVideoCover, downloadInfo.getVideoCover());
int firstSubtitleStatus = downloadInfo.getFirstSubtitleStatus();
if (firstSubtitleStatus == 2) {
holder.tvSubtitleState.setVisibility(View.VISIBLE);
holder.tvSubtitleState.setText("下载字幕失败");
} else {
holder.tvSubtitleState.setVisibility(View.INVISIBLE);
}
return convertView;
}
if (convertView == null) {
holder = new ViewHolder();
convertView = View.inflate(context, R.layout.item_downloaded_video, null);
holder.tv_filesize = convertView.findViewById(R.id.tv_filesize);
holder.titleView = convertView.findViewById(R.id.downloaded_title);
holder.iv_video_cover = convertView.findViewById(R.id.iv_video_cover);
holder.tv_subtitle_state = convertView.findViewById(R.id.tv_subtitle_state);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
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, downloadInfo.getEnd()));
}else {
holder.tv_filesize.setVisibility(View.INVISIBLE);
}
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("下载字幕失败");
}else {
holder.tv_subtitle_state.setVisibility(View.INVISIBLE);
}
return convertView;
}
public class ViewHolder {
public TextView titleView;
public TextView tv_filesize;
public TextView tv_subtitle_state;
public ImageView iv_video_cover;
}
public static class ViewHolder {
public TextView titleView;
public TextView tvFileSize;
public TextView tvSubtitleState;
public ImageView ivVideoCover;
}
}
......@@ -13,11 +13,8 @@ import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;
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.R;
import com.bokecc.vod.utils.MultiUtils;
......
......@@ -14,7 +14,6 @@ import androidx.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;
......@@ -26,174 +25,174 @@ import java.util.TimerTask;
/**
* DownloadService,用于支持后台下载
*
*
* @author CC
*/
public class DownloadService extends Service {
private NetChangedReceiver netReceiver;
//是否使用移动网络下载,可根据实际自行设置
private boolean isUseMobieNetwork = true;
private boolean isPaused = false;
Timer timer = new Timer();
@Override
public void onCreate() {
super.onCreate();
if (netReceiver == null) {
netReceiver = new NetChangedReceiver();
}
IntentFilter filter = new IntentFilter();
filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
registerReceiver(netReceiver, filter);
timer.schedule(new TimerTask() {
@Override
public void run() {
if (isUseMobieNetwork){
VodDownloadManager.getInstance().update();
}else {
int netWorkStatus = MultiUtils.getNetWorkStatus(DownloadService.this);
//网络状态 0:无网络 1:WIFI 2:移动网络
if (netWorkStatus==1){
VodDownloadManager.getInstance().update();
isPaused = false;
}else {
if (!isPaused){
VodDownloadManager.getInstance().pauseAllDownload();
isPaused = true;
}
}
}
}
}, 1 * 1000, 1 * 1000);
//监听下载完成的文件
VodDownloadManager.getInstance().setOnDownloadFinishListener(new VodDownloadManager.OnDownloadFinishListener() {
@Override
public void onDownloadFinish(final VodDownloadBean vodDownloadBean) {
String fileName = vodDownloadBean.getFileName();
if (DataSet.hasDownloadInfo(fileName)){
DownloadInfo downloadInfo = DataSet.getDownloadInfo(fileName);
saveDownloadInfo(vodDownloadBean, downloadInfo);
DataSet.updateDownloadInfo(downloadInfo);
if (onUpdateDownloadedView!=null){
onUpdateDownloadedView.updateDownloadedView(downloadInfo);
}
}else {
DownloadInfo downloadInfo = new DownloadInfo();
saveDownloadInfo(vodDownloadBean, downloadInfo);
DataSet.addDownloadInfo(downloadInfo);
if (onUpdateDownloadedView!=null){
onUpdateDownloadedView.updateDownloadedView(downloadInfo);
}
}
}
});
}
private void saveDownloadInfo(VodDownloadBean vodDownloadBean, DownloadInfo downloadInfo) {
downloadInfo.setVideoId(vodDownloadBean.getVideoId());
downloadInfo.setTitle(vodDownloadBean.getFileName());
downloadInfo.setFormat(vodDownloadBean.getFormat());
downloadInfo.setDownloadMode(vodDownloadBean.getDownloadMode());
downloadInfo.setVideoCover(vodDownloadBean.getVideoCover());
downloadInfo.setEnd(vodDownloadBean.getEnd());
downloadInfo.setStatus(vodDownloadBean.getStatus());
downloadInfo.setCreateTime(new Date());
downloadInfo.setDefinition(vodDownloadBean.getDefinition());
downloadInfo.setFirstSubtitleStatus(vodDownloadBean.getFirstSubtitleStatus());
downloadInfo.setSecondSubtitleStatus(vodDownloadBean.getSecondSubtitleStatus());
downloadInfo.setSubtitleNum(vodDownloadBean.getSubtitleNum());
downloadInfo.setSubtitleModel(vodDownloadBean.getSubtitleModel());
downloadInfo.setMarqueeData(vodDownloadBean.getMarqueeData());
}
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onDestroy() {
timer.cancel();
VodDownloadManager.getInstance().pauseAllDownload();
if (netReceiver !=null){
unregisterReceiver(netReceiver);
}
super.onDestroy();
}
public interface OnUpdateDownloadedView {
void updateDownloadedView(DownloadInfo downloadInfo);
}
private static OnUpdateDownloadedView onUpdateDownloadedView;
public static void setOnUpdateDownloadedView(OnUpdateDownloadedView updateDownloadedView) {